Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pmatthews05/9d20312eb82206f6da8698de7ea1e6fe to your computer and use it in GitHub Desktop.
Save pmatthews05/9d20312eb82206f6da8698de7ea1e6fe to your computer and use it in GitHub Desktop.
Trying to hack SharePoint Online to Configure Site Collection Tenant default timezone (context here: https://twitter.com/cann0nf0dder/status/1260607421111767042)
<#
.SYNOPSIS
Updates the Default TimeZone for sites in the Admin Centre.
.EXAMPLE
Using Your Account.
First connect using Connect-PnPOnline -PnPO365ManagementShell -url:<Tenant-Admin> -launchBrowser
.\TenantSiteCollectionDefaultTimeZone.ps1 -TimeZoneId:2
.EXAMPLE
Using Certificate and AppId ()
First connect using Connect-PnpOnline -ClientId:<ClientId> -Tenant:<Tenant> -CertificatePath:<PathToCert> -CertificatePassword:<SecureStringPassword> -Url:<Tenant-Admin>
.\TenantSiteCollectionDefaultTimeZone.ps1 -TimeZoneId:2 -App:$true
.EXAMPLE
Using ClientID and Secret
First Connect using Connect-PnPOnline -Url:<Tenant-Admin> -AppId:<ClientId> -AppSecret:<ClientSecret>
.\TenantSiteCollectionDefaultTimeZone.ps1 -TimeZoneId:2 -App:$true
#>
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory)]
[int]
$TimeZoneId,
[bool]
$App = $false
)
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'
$siteUrl= (Get-PnPWeb).Url
$endpoint = "$($siteUrl)/_api/SPOInternalUseOnly.TenantAdminSettings"
if($app){
$accessToken = Get-PnPAppAuthAccessToken
}else
{
$accessToken = Get-PnPAccessToken
}
$authHeader = @{
'Content-Type' = 'application/json; charset=utf-8'
'Authorization' = 'Bearer ' + $accessToken
}
$itemPayload = "{ ""TenantDefaultTimeZoneId"": { ""Value"":$TimeZoneId }}"
try {
Write-Information -MessageData:"Updating TimeZoneID to $TimeZoneId..."
$response = Invoke-RestMethod -Uri:$endpoint -Method:Patch -Body $itemPayload -Headers:$authHeader
Write-Information -MessageData:"Done"
} catch {
$err=$_.Exception
Write-Information -MessageData:$err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment