I am looking for a way to add a site collection owner to personal site of a user.
I can set the ctx.Site.Owner for other site collections, but for personal sites I am receiving Unauthorized exception at ctx.ExecuteQuery(). I am a global administrator for the tenant.
The same functionality is possible via GUI:

enter image description here

Thanks in advance!

1 Answer 1


I have a Powershell function in my profile (it also handles loading all the CSOM modules too) that looks like this:

#This will handle iterating through all the OD4B sites that have been provisioned
    #and setting an eDiscovery SCA and any other SCAs as necessary
    $sca = "[email protected]"

    $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
    $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($me, $Password)
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($MysiteHost)
    $Context.Credentials = $Creds

    #Identify users in the Site Collection
    $Users = $Context.Web.SiteUsers

    #Create People Manager object to retrieve profile data
    $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)

    Foreach ($User in $Users)
        $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
        If ($UserProfile.Email -ne $null){
            $UPP = $UserProfile.UserProfileProperties

            else {
                Write-Host "Setting SCAs for " $UserProfile.DisplayName -ForegroundColor Green
                Set-SPOUser -Site $UserProfile.PersonalUrl -LoginName $sca -IsSiteCollectionAdmin $true

This iterates over all the OD4B sites and sets the owner, it could be adapted easily enough to supply a user or a URL.


Your Answer

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

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