Forum Discussion
null null
Oct 23, 2017Iron Contributor
adding domain user to site collection admin for a users od4b site collection
I am trying to write a powershell script to change the Locale from En-US to EN-UK for which i have written powershell script to achieve that. However it does not execute as the the admin needs to to be made site collection secondary admin at least for the one drive for business site. so in the middle of the script before the last execute method i need to add the AdminUser to its site collection administrators. As you know i have used CSOM below; i want to achieve that using CSOM;
I have
tenant url, admin, user od4b url.
#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles") #Specify tenant admin <$AdmiUser = "first.Lastname@domain.abc.uk"> $Password = Read-Host -Prompt "Please enter your password" -AsSecureString $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUser,$Password) #Configure MySite Host URL < $SiteURL = "https://tenant-my.sharepoint.com/"> #Bind to MySite Host Site Collection $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $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) $UserProfile = $PeopleManager.GetPropertiesFor('<sample user>'') $Context.Load($UserProfile) $Context.ExecuteQuery() If ($UserProfile.Email -ne $null) { Write-Host "Updating OD4B site for User:" $User.LoginName -ForegroundColor Green #Bind to OD4B Site and change locale $OD4BSiteURL = $UserProfile.PersonalUrl $Context2 = New-Object Microsoft.SharePoint.Client.ClientContext($OD4BSiteURL) Foreach ($User in $OD4BSiteURL) { $Context2.Credentials = $Creds $Context2.ExecuteQuery() #$Context2.Load($web); #$Context2.Load($RegionalSettings); Write-Host $User $Context2.Web.RegionalSettings.LocaleId = "2057" $Context2.Web.Update() $Context2.ExecuteQuery() } }
- Manidurai MohanamariappanIron Contributor
Hi,
you can't do with csom because if you add secondary admin for ODFB site using csom you must be a site collection admin in that site . so you can use "Set-SPOUser -Site $sitename -LoginName $secondaryadmin -IsSiteCollectionAdmin $true"
You can refer the following link
- Sorry, but I'm not following you....are you having any errors when executing the script?