Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Azure Automation script to set the SharePoint Site Locale
[CmdletBinding()]
Param
(
[string]$SiteUrl
)
# Refer to https://github.com/pnp/PnP-PowerShell/tree/master/Samples/Connect.AzureAutomation
# for setting up Azure Automation using an App Only connection to SharePoint Online
# Retrieves from the Azure Automation variables and certificate stores
# the details for connecting to SharePoint Online
$azureAutomateCreds = Get-AutomationPSCredential -Name 'AzureAppCertPassword'
$appId = Get-AutomationVariable -Name "AppClientId"
$appAdTenant = Get-AutomationVariable -Name "AppAdTenant"
$appCert = Get-AutomationCertificate -Name "AzureAppCertificate"
# Site Template List
try {
Write-Verbose "Running Script..."
# Export the certificate and convert into base 64 string
$base64Cert = [System.Convert]::ToBase64String($appCert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12))
Write-Verbose "Connected to SharePoint Online Site"
# Connect to the standard SharePoint Site
$siteConn = Connect-PnPOnline -ClientId $appId -CertificateBase64Encoded $base64Cert `
-CertificatePassword $azureAutomateCreds.Password `
-Url $SiteUrl -Tenant $appAdTenant -ReturnConnection
$LocaleId = 2057 # UK
$TimeZoneId = 2 # London
$web = Get-PnPWeb -Includes RegionalSettings,RegionalSettings.TimeZones -Connection $siteConn
$timeZone = $web.RegionalSettings.TimeZones | Where-Object {$_.Id -eq $TimeZoneId}
$web.RegionalSettings.LocaleId = $LocaleId
$web.RegionalSettings.TimeZone = $timeZone
$web.Update()
Invoke-PnPQuery
}
catch {
#Script error
Write-Error "An error occurred: $($PSItem.ToString())"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.