Forum Discussion
Office 365: Add accounts into the Site collection administrators list via PowerShell and CSOM
Fromelard This method fails for me with the error "The user does not exist or is not unique". Same with Set-PnPTenantSite and Set-SPOUser as suggested by Mikael Svenson. I tested this on two tenants, one that automatically assigns these roles as site admins for new sites and one that don't and the behavior is the same.
Example code:
Connect-PnPOnline <a href="https://contoso-admin.sharepoint.com" target="_blank">https://contoso-admin.sharepoint.com</a>
Set-PnPTenantSite -Url <a href="https://contoso.sharepoint.com/project" target="_blank">https://contoso.sharepoint.com/project</a> -Owners "c:0-.f|rolemanager|s-1-1-11-11111111-111111-111111-1111"
- FromelardJan 09, 2020Iron Contributor
Sorry for that, but as you can see into that publication created long time ago.
> Microsoft is changing the SharePoint management way and CSOM is probably not anymore the best approach to manage Administrative permission.
> Site Collection administrator is also now out of vision defined with TEAMS
So all that strategical change define by Microsoft since years could explain why this kind of command/script/code could be not usable anymore.
Can you check with PnP instead of ?
Sorry for that
Fab
- Gabriel SmoljarJan 17, 2020Brass Contributor
I did some digging and found that the login names are no longer applicable. Now they are in the form "c:0t.c|tenant|32e1b7a8-foob-are8-8fb7-827c407110c0" where the guid at the end is the object id of the directory role you want to add. You can find these using Get-AzureADDirectoryRole PowerShell command. They are different for each tenancy unfortunately.