Created
July 4, 2018 21:39
-
-
Save Windos/40c597c23a3da169a2da3a2468b67be8 to your computer and use it in GitHub Desktop.
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
### GetMailAutoReply.ps1 | |
<# | |
.SYNOPSIS | |
Gets a users current auto reply message and state. | |
#> | |
param | |
( | |
[Parameter(Mandatory = $true, | |
HelpMessage="What user to lookup?")] | |
[ValidateNotNullOrEmpty()] | |
[String]$Username | |
) | |
begin {} | |
process { | |
Write-Verbose -Message "Opening session to Exchange server" | |
$Cred = Get-StoredCredential -Target 'ServiceAccountWithExchangePermissions' | |
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange.example.com/powershell -Authentication Kerberos -Credential $Cred | |
$null = Import-PSSession -Session $ExSession -DisableNameChecking | |
Write-Verbose -Message "Session opened" | |
Write-Verbose -Message "Querying Auto Reply" | |
try { | |
Get-MailboxAutoReplyConfiguration -Identity $Username | Select-Object -Property AutoReplyState, StartTime, EndTime, ExternalAudience, InternalMessage, ExternalMessage | |
} catch { | |
Write-Host -Object '[[span|psbold|Error!]]' | |
} | |
Write-Verbose -Message "Closing session to Exchange server" | |
(Get-PSSession | Where-Object -FilterScript {$_.ConfigurationName -eq 'Microsoft.Exchange'}) | Remove-PSSession | |
Write-Verbose -Message "Session closed" | |
} | |
end {} | |
### SetMailAutoReply.ps1 | |
<# | |
.SYNOPSIS | |
Sets a users current auto reply message and state. | |
#> | |
param | |
( | |
[Parameter(Mandatory = $true, | |
HelpMessage="What user to lookup?")] | |
[ValidateNotNullOrEmpty()] | |
[String]$Username, | |
[Switch]$Enabled, | |
[Switch]$ExternalReply, | |
#WEBJEA-Multiline | |
[String]$InternalMessage = '', | |
#WEBJEA-Multiline | |
[String]$ExternalMessage= '' | |
) | |
begin {} | |
process { | |
Write-Verbose -Message "Opening session to Exchange server" | |
$Cred = Get-StoredCredential -Target 'ServiceAccountWithExchangePermissions' | |
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange.example.com/powershell -Authentication Kerberos -Credential $Cred | |
$null = Import-PSSession -Session $ExSession -DisableNameChecking | |
Write-Verbose -Message "Session opened" | |
Write-Verbose -Message "Setting Auto Reply" | |
try { | |
$State = $null | |
if ($Enabled) { | |
$State = 'Enabled' | |
} else { | |
$State = 'Disabled' | |
} | |
$Audience = $null | |
if ($ExternalReply) { | |
$Audience = 'All' | |
} else { | |
$Audience = 'None' | |
} | |
Set-MailboxAutoReplyConfiguration -Identity $Username -AutoReplyState $State -ExternalAudience $Audience -InternalMessage $InternalMessage -ExternalMessage $ExternalMessage | |
} catch { | |
Write-Host -Object '[[span|psbold|Error!]]' | |
} | |
Write-Verbose -Message "Closing session to Exchange server" | |
(Get-PSSession | Where-Object -FilterScript {$_.ConfigurationName -eq 'Microsoft.Exchange'}) | Remove-PSSession | |
Write-Verbose -Message "Session closed" | |
} | |
end {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment