0

I am trying to get a list of users OneDrive For Business site collections Locale ID's. I have been trying to use this site to help me achieve this. I have changed the bottom section to try and get the Microsoft.SharePoint.Client.RegionalSettings.LocaleId for each site collection but I cannot seem to pull anything back for the LocaleID

#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)
        {
        Write-Host "User:" $User.LoginName -ForegroundColor Green
        #Bind to OD4B Site and change locale
        $OD4BSiteURL = $UserProfile.PersonalUrl
        $Context2 = New-Object Microsoft.SharePoint.Client.ClientContext($OD4BSiteURL)
        Write-Host "localeID:" $OD4BSiteURL.RegionalSettings.LocaleId -ForegroundColor Yellow

        }}

Would someone be able to assist to let me know where I am going wrong?

0

With some fiddling I got it. Don't know if it is the most streamlined way but it works well.

Here is my full script if anyone ever finds they need to do the same -

        #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
        $User = "ADMINACCOUNT"
        $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
        $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)


        #Configure MySite Host URL
        $SiteURL = "https://TENANT-admin.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()



$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)
        {
        Write-Host "User:" $User.LoginName -ForegroundColor Green
        #Bind to OD4B Site and change locale
        $OD4BSiteURL = $UserProfile.PersonalUrl
        $Context2 = New-Object Microsoft.SharePoint.Client.ClientContext($OD4BSiteURL)
        Write-Host $OD4BSiteURL -ForegroundColor Yellow

        Foreach ($User in $OD4BSiteURL)
{
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext("$user")
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)


$web = $ctx.Web;
$RegionalSettings = $ctx.Web.RegionalSettings
$ctx.Load($web);
$ctx.Load($RegionalSettings);
$ctx.ExecuteQuery();

Write-Host $User $RegionalSettings.LocaleId

}
        }}

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.