2

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!

3

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 = "user@domain.com"

    $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
    $Context.Load($Users)
    $Context.ExecuteQuery()

    #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)
        $Context.Load($UserProfile)
        $Context.ExecuteQuery()
        If ($UserProfile.Email -ne $null){
            $UPP = $UserProfile.UserProfileProperties

            if($UserProfile.PersonalUrl.Contains("PersonImmersive")){
                continue
            }
            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, privacy policy and cookie policy

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