-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSP-UserTimezone.ps1
69 lines (63 loc) · 2.83 KB
/
SP-UserTimezone.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
Must be run from SP Management Shell on the SharePoint Server
#>
function Get-SPUserTimeZone() {
<# Function to get the current SharePoint a time zone for a user. #>
[Cmdletbinding()]
param(
[parameter(mandatory = $true, HelpMessage = "for example http://theportal.ourfirm.com")][String] $portalUrl,
[parameter(mandatory = $true, HelpMessage = "for example firm\jdoe")][String] $userLogin
)
$web = (Get-SPSite -Identity $portalUrl).RootWeb
$user = $web.SiteUsers | Where-Object { $_.userLogin -eq $userLogin }
if ($user) {
$tz = $user.RegionalSettings.TimeZone
Write-Verbose "Current timezone setting for $($user.displayName): $($tz.ID) - $($tz.Description)"
return $tz
}
else {
Write-Error "Login not found for $userLogin"
}
}
function Set-SPUserTimeZone() {
<# Function to SET user time zones #>
[Cmdletbinding()]
param(
[parameter(mandatory = $true, HelpMessage = "for example http://theportal.ourfirm.com")][String] $portalUrl,
[parameter(mandatory = $true, HelpMessage = "for example firm\jx123456")][String] $userLogin,
[parameter(mandatory = $true, HelpMessage = "10 = EST or 13=PST")][uint16] $timezoneID
)
$web = (Get-SPSite -Identity $portalUrl).RootWeb
$user = $web.SiteUsers | Where-Object { $_.userLogin -eq $userLogin }
if ($user) {
$currentTZ = $user.RegionalSettings.TimeZone
Write-Verbose "Current timezone setting for $($user.displayname) : $($currentTZ.description)"
$regSettings = new-object Microsoft.SharePoint.SPRegionalSettings($web, $true);
$newTimeZone = $regSettings.TimeZones | Where-Object { $_.ID -eq "$timezoneID" }
$regSettings.TimeZone.ID = $newTimeZone.ID
$user.RegionalSettings = $regSettings
$user.Update()
$newTZ = $user.RegionalSettings.TimeZone
Write-Verbose "New timezone setting for $($user.displayName) : $($newtz.Description)"
return $newTZ
}
else {
Write-Error "Login not found for $userLogin"
}
}
function Get-SPTimeZones() {
<# Function get all available SP Timezones by ID and Description #>
[Cmdletbinding()]
param(
[parameter(mandatory = $true, HelpMessage = "for example http://theportal.ourfirm.com")][String] $portalUrl
)
$web = (Get-SPSite -Identity $portalUrl).RootWeb
$r = new-object Microsoft.SharePoint.SPRegionalSettings($web, $true);
return $r.TimeZones
}
<# sample code
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$portalUrl = 'https://intranet.yourfirm.net'
Set-SPUserTimeZone -portalUrl $portalUrl -userLogin "firm\someusernetworkid" -timezoneID 13
Get-SPTimeZones -portalUrl https://portal2021.handshakedemo.com | Sort-Object -property ID | Format-Table id, description
#>