Update TimeZone Regional Settings in Office 365 using Powershell
-
07-10-2020 - |
سؤال
I would like to update regional settings (TimeZone to be exact) in 1000 sites.
I found the right property $ctx.Web.RegionalSettings.TimeZone
, but it is read-only. I searched for any functions allowing to modify the TimeZone, but did not find any (no TimeZones.Add()
or .SetAsDefault()
).
- Manual change is not an option.
- LocaleID is not the same as TimeZone. Please do not offer solutions to change LocaleID.
- There are no issues connecting to SPO or reading data. I can retrieve/read the current Zone with code:
13 (UTC-08:00) Pacific Time (US and Canada)
Question
How can I update $ctx.Web.RegionalSettings.TimeZone
for 1000 sites using code?
المحلول
The answer is to set TimeZone as a TimeZone:
$ctx.Load($ctx.Web)
$ctx.Load($ctx.Web.RegionalSettings.TimeZone)
$ctx.Load($ctx.Web.RegionalSettings.TimeZones)
$ctx.ExecuteQuery()
$ctx.Web.RegionalSettings.TimeZone=$ctx.Web.RegionalSettings.TimeZones.GetbyID($TimeZoneID)
$ctx.Web.Update()
$ctx.ExecuteQuery()
The answer comes from the amazing Vesa Juvonen and his blog: http://blogs.msdn.com/b/vesku/archive/2015/04/10/new-sharepoint-csom-version-released-for-office-365.aspx
لا تنتمي إلى sharepoint.stackexchange