Last active
December 21, 2015 10:49
-
-
Save janikvonrotz/6294947 to your computer and use it in GitHub Desktop.
PowerShell: Set Exchange OnlineConfigurations
#PowerShell
#ExchangeOnline
#Office365
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-16"?> | |
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<RegistrationInfo> | |
<Date>2013-03-20T14:18:21.6393172</Date> | |
<Author>Janik von Rotz (www.janikvonrotz.ch)</Author> | |
<Description>Exchange Online Settings</Description> | |
</RegistrationInfo> | |
<Triggers> | |
<CalendarTrigger> | |
<StartBoundary>2013-01-01T03:00:00</StartBoundary> | |
<Enabled>true</Enabled> | |
<ScheduleByDay> | |
<DaysInterval>1</DaysInterval> | |
</ScheduleByDay> | |
</CalendarTrigger> | |
</Triggers> | |
<Settings> | |
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>false</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<IdleSettings> | |
<StopOnIdleEnd>true</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>false</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>P3D</ExecutionTimeLimit> | |
<Priority>7</Priority> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe</Command> | |
<Arguments>C:\Powershell-Profile\scripts\Set-EOConfig.ps1</Arguments> | |
<WorkingDirectory>C:\Powershell-Profile\scripts</WorkingDirectory> | |
</Exec> | |
</Actions> | |
</Task> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
$Metadata = @{ | |
Title = "Set Exchange Online Configurations" | |
Filename = "Set-EOConfig.ps1" | |
Description = "" | |
Tags = "powershell, office, 365, exchange, online, settings" | |
Project = "" | |
Author = "Janik von Rotz" | |
AuthorContact = "http://janikvonrotz.ch" | |
CreateDate = "2014-01-21" | |
LastEditDate = "2014-01-21" | |
Url = "https://gist.github.com/6294947" | |
Version = "1.0.0" | |
License = @' | |
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Switzerland License. | |
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ch/ or | |
send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | |
'@ | |
} | |
#> | |
try{ | |
#--------------------------------------------------# | |
# settings | |
#--------------------------------------------------# | |
$Language = "de-CH" | |
$TimeZone = "W. Europe Standard Time" | |
$DateFormat = "dd.MM.yyyy" | |
$HtmlSignatureTemplate = "vbl signature.html" | |
$TextSignatureTemplate = "vbl signature.txt" | |
$SignatureCompanyPhoneNumber = "+41 41 369 65 65" | |
$SignatureCompanyFaxNumber = "041 369 65 00" | |
#--------------------------------------------------# | |
# modules | |
#--------------------------------------------------# | |
Import-Module ActiveDirectory | |
#--------------------------------------------------# | |
# sessions | |
#--------------------------------------------------# | |
$Credential = Import-PSCredential $(Get-ChildItem -Path $PSconfigs.Path -Filter "Office365.credentials.config.xml" -Recurse).FullName | |
$s = New-PSSession -ConfigurationName Microsoft.Exchange ` | |
-ConnectionUri https://ps.outlook.com/powershell ` | |
-Credential $(Get-Credential -Credential $Credential) ` | |
-Authentication Basic ` | |
-AllowRedirection | |
Import-PSSession $s | |
#--------------------------------------------------# | |
# main | |
#--------------------------------------------------# | |
$ADUsers = Get-ADUser -Filter {Mail -like "*"} -Properties sn, telephoneNumber, title | |
$Mailboxes = Get-Mailbox | |
foreach($Mailbox in $Mailboxes){ | |
Write-Progress -Activity "Update settings" -status $($Mailbox.Name) -percentComplete ([Int32](([Array]::IndexOf($Mailboxes, $Mailbox)/($Mailboxes.count))*100)) | |
Write-Host "Set mailbox language settings for $($Mailbox.Name)" | |
Set-MailboxRegionalConfiguration $Mailbox.Alias -Language $Language -TimeZone $TimeZone -LocalizeDefaultFolderName -DateFormat $DateFormat | |
Write-Host "Set signature for $($Mailbox.Name)" | |
$ADUsers | where{$_.UserPrincipalName -eq $Mailbox.UserPrincipalName} | select -First 1 | %{ | |
$Html = get-Content -Path $(Get-ChildItem -Path $PStemplates.Path -Filter $HtmlSignatureTemplate -Recurse).FullName | |
$Text = get-Content -Path $(Get-ChildItem -Path $PStemplates.Path -Filter $TextSignatureTemplate -Recurse).FullName | |
$PhoneNumber = $(if($_.telephoneNumber -eq $null){$SignatureCompanyPhoneNumber}else{$_.telephoneNumber}) | |
$Html = $Html -replace "%%Firstname%%",$_.givenname ` | |
-replace "%%Lastname%%",$_.sn ` | |
-replace "%%Title%%",$_.title ` | |
-replace "%%PhoneNumber%%",$PhoneNumber ` | |
-replace "%%FaxNumber%%",$SignatureCompanyFaxNumber | |
$Text = $Text -replace "%%Firstname%%",$_.givenname ` | |
-replace "%%Lastname%%",$_.sn ` | |
-replace "%%Title%%",$_.title ` | |
-replace "%%PhoneNumber%%",$PhoneNumber ` | |
-replace "%%FaxNumber%%",$SignatureCompanyFaxNumber | |
Set-MailboxMessageConfiguration -Identity $Mailbox.Alias -SignatureHtml $Html -AutoAddSignature $true -SignatureText $Text | |
} | |
} | |
}catch{ | |
Write-PPErrorEventLog -Source "Exchange Online Settings" -ClearErrorVariable | |
}finally{ | |
Remove-PSSession $s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment