Skip to content

Instantly share code, notes, and snippets.

@Windos
Created July 4, 2018 21:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Windos/40c597c23a3da169a2da3a2468b67be8 to your computer and use it in GitHub Desktop.
Save Windos/40c597c23a3da169a2da3a2468b67be8 to your computer and use it in GitHub Desktop.
### 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