Feb 25 2019 04:26 AM
Hi,
I have made powershell script to provision modern team and communication sites.
I have a share point list where user selects relevant information for this site.
The user also selects the owner and administrators for this site and they should be updated immediately after the new site is provisioned.
I have tried the below code but it doesn't work.
[Microsoft.SharePoint.Client.FieldUserValue] $owner = $item["Owner"]
$owneremail = $owner.Email
Connect-PnPOnline $siteURL
#Now we have access on the SharePoint site for any operations
$context_2 = Get-PnPContext
$web = Get-PnPWeb
$web
$context_2.Load($web, $web.WebTemplate)
$context_2.ExecuteQuery()
Add-PnPSiteCollectionAdmin -Owners $owneremail
Also tried
$siteURL = "https://SomeSite.sharepoint.com/sites/SubSite1"
Connect-PnPOnline $siteURL
Set-PnPSite -Identity $siteURL -Owners "User@SomeSite.com"
Kindly assist with the same.
Feb 25 2019 06:59 AM
Hi, have you tried using the "Set-SPOUser" from SPO Management Shell instead of PnP ?
https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/set-spouser?view=sharepoint-ps
Try:
Connect-SPOService -Url "https://somesite-admin.sharepoint.com/"
Set-SPOUser -LoginName "User@SomeSite.com" -IsSiteCollectionAdmin $true -Site $siteURL