Share via

Fail to update time zone

developer sp1 461 Reputation points
2020-10-01T01:35:36.757+00:00

Connect-PnPOnline $SiteURL -UseWebLogin

Get the Web

$web = Get-PnPWeb -Includes RegionalSettings.TimeZones

Get the time zone

$Timezone = $Web.RegionalSettings.TimeZones | Where {$_.Description -eq $TimezoneName}

If($Timezone -ne $Null)
{

Update time zone of the site

$Web.RegionalSettings.TimeZone = $Timezone
$Web.Update()
Write-host "Timezone Updated Successfully!" -ForegroundColor Green
}

Tried with this powershell, but fail to update time zone, the time zone didn't change at all

Maybe missed some key point in the code snippet ?

Can you help to correct or provide some other CSOM code please ?

Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments

Answer accepted by question author

ZhengyuGuo 10,591 Reputation points Moderator
2020-10-01T07:01:38.347+00:00

Hi @developer sp1 ,

Here is a complete code demo to set time zone for your reference:

$SiteURL = "https://crescent.sharepoint.com/sites/marketing"  
$TimezoneName = "(UTC+04:00) Abu Dhabi, Muscat"  
   
#Connect to SharePoint Online with PnP PowerShell  
Connect-PnPOnline $SiteURL -UseWebLogin  
   
#Get the Web  
$web = Get-PnPWeb -Includes RegionalSettings.TimeZones  
   
#Get the time zone  
$Timezone  = $Web.RegionalSettings.TimeZones | Where {$_.Description -eq $TimezoneName}  
   
If($Timezone -ne $Null)  
{  
    #Update time zone of the site  
    $Web.RegionalSettings.TimeZone = $Timezone  
    $Web.Update()  
    Invoke-PnPQuery  
    Write-host "Timezone Updated Successfully!" -ForegroundColor Green  
}  
else  
{  
    Write-host "Timezone $TimezoneName not found!" -ForegroundColor Yellow  
}  

You missed Invoke-PnPQuery in your code snippet which applied the changes.


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.