0

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

$context_2 = Get-PnPContext

$web = Get-PnPWeb

$context_2.Load($web, $web.WebTemplate)

$context_2.ExecuteQuery()

Add-PnPSiteCollectionAdmin -Owners $owneremail

--------------------------------------------------------------------------

I have also tried this :

    $siteURL = "https://SomeSite.sharepoint.com/sites/SubSite"

    Connect-PnPOnline $siteURL

    Set-PnPSite -Identity $siteURL -Owners "Owner@SomeSite.com"

Doesn't work.

Kindly assist with the same.

1

You can use the PnP PowerShell command as below to set the site collection administrator for modern sites:

Set-PnPTenantSite -Url $siteURL -Owners "Owner@SomeSite.com"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.