0

I have one SharePoint site e.g. test1 - "https://abc.sharepoint.com/sites/test1".

I have granted SharePoint Administrator role to User1 in the Microsoft 365 Admin Center (Note - User1 does not have any permissions to the site test1 but has assigned a role of SharePoint Administrator through admin center)

enter image description here

I want to add the user User2 as a site collection admin to the site test1 using the PowerShell.

But when I am trying to connect to the site test1 using PnP command Connect-PnPOnline and credentials of User1, I am getting The remote server returned an error: (401) Unauthorized..

Is it possible to add site collection admin to the site test1 using CSOM PowerShell + User having SharePoint Administrator role(User1 in this case).

or is there any other workaround?

Please guide me on this.

Thanks!

1 Answer 1

0

“User1” cannot add new site collection admin to "test1" site collection using CSOM PowerShell.

"User1" must has Global Administrator permission can run the following script commands

$AdminURL = "https://contoso-admin.sharepoint.com/"
$AdminName = "[email protected]"

$SiteCollURL = "https://contoso.sharepoint.com/sites/test1/"
$SiteCollectionAdmin = "[email protected]"
 
#User Names Password to connect 
$SecurePWD = read-host -assecurestring "Enter Password for $AdminName" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $SecurePWD

Connect-SPOService -url $AdminURL -credential $Credential

#Add Site collection Admin
Set-SPOUser -site $SiteCollURL -LoginName $SiteCollectionAdmin -IsSiteCollectionAdmin $True

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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