Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://techcommunity.microsoft.com/t5/Office-365-Groups/Time-Zone-Settings-for-O365-Groups-SharePoint-Site/td-p/26301
- # https://blogs.technet.microsoft.com/heyscriptingguy/2014/04/24/create-and-manage-sharepoint-online-sites-by-using-powershell/
- # Requires https://www.microsoft.com/en-ie/download/details.aspx?id=35585 to run
- #Links to investigate
- $TimezoneValue= "(GMT) Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London"
- $localeid = 2057
- $AuthStore = "\\fcitapps\ProgramStore\UserCreation\Credentials\" + $env:USERNAME
- $Auth = Get-Content $AuthStore | ConvertTo-SecureString
- $O365Username = $env:USERNAME + "@domain.com"
- $LocalUsername = "DOMAIN\" + $env:USERNAME
- #Create a credential with your username and retrieved password.
- $O365Cred = New-Object System.Management.Automation.PsCredential($O365Username, $Auth)
- $LocalCred = New-Object System.Management.Automation.PsCredential($LocalUsername, $Auth)
- #Generate a new Office 365 Powershell session.
- $s2=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $O365Cred -Authentication Basic -AllowRedirection
- Import-PSSession -Session $s2
- #Load the Sharepoint prerequisites
- Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location)
- Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location)
- #Create credentials for connecting to Sharepoint sites
- $SPOUsername = "globaladmin@domain.com"
- $SPOPassword = Read-Host -Prompt "Enter password for $SPOUsername" -AsSecureString
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($SPOUsername,$SPOPassword)
- #Load all the Sharepoint groups
- $Groups =Get-UnifiedGroup |Where-Object {$_.SharePointSiteUrl -ne $null}|select SharePointSiteUrl
- foreach($Group in $Groups.SharePointSiteUrl)
- {
- Write-Host $Group
- $Site = $Group
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
- $Context.Credentials = $Creds
- $TimeZones = $Context.Web.RegionalSettings.TimeZones
- Try{
- $Context.Load($TimeZones)
- $Context.ExecuteQuery()
- $RegionalSettings = $Context.Web.RegionalSettings
- $Context.Load($RegionalSettings)
- $Context.ExecuteQuery()
- Write-Host $RegionalSettings.LocaleID
- Try{
- $TimeZone = $TimeZones | Where {$_.Description -eq $TimezoneValue}
- $RegionalSettings.TimeZone = $TimeZone
- $RegionalSettings.Localeid = $localeid
- $Context.Web.Update()
- $Context.ExecuteQuery()
- Write-Host "Changed"
- }
- Catch{
- Write-Host $Error[0] -ForegroundColor Red
- Write-Host "Unable to modify"
- }
- }
- Catch{
- Write-Host "Unauthorised" -ForegroundColor Red
- }
- Write-Host "----------"
- }
- Get-PSSession | Remove-PSSession
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement