0

This is my first time trying to use CSOM with Powershell, I would like to display the $web.RegionalSettings.LocaleId of a site.

I have created the script that will change the site Locale to en-UK which is a good if my only requirement is to do this on one site.

My aim is to go through all the sites in my tenant and gather all which don't equal '2057' into a list.

When I add Write-Host $web.RegionalSettings.LocaleId before setting the value it comes back blank, but in the script below it works fine after setting the value, any idea why?

 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext("SITEURL")

$username = 'USERACCOUNT'

$password = Read-Host -Prompt "Password for $username" –AsSecureString

 $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)


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

$web.RegionalSettings.LocaleId = 2057;
$web.Update();
Write-Host $web.RegionalSettings.LocaleId
$ctx.ExecuteQuery();
1

You need to load the RegionalSettings object. Try the below code:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext("SITEURL")

$username = 'USERACCOUNT'

$password = Read-Host -Prompt "Password for $username" –AsSecureString

$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 $RegionalSettings.LocaleId

$web.RegionalSettings.LocaleId = 2057;
$web.Update();
$ctx.ExecuteQuery();
Write-Host $web.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.