Home > PowerShell > Exchange – Get all active Out Of Office responses

Exchange – Get all active Out Of Office responses

Today, I got asked to change an Out Of Office reply for a member of staff who had left the organisation. There wasn’t anything rude in what they had written, it just wasn’t as professional as we would have liked.

As we are currently having a larger than usual turnover of staff, it occurred to me that it would be quite useful to have a list of all the active Out Of Office messages.

The following PowerShell script creates an html with the active Out Of Office messages:

$OutputFile = "C:\Scripts\OutOfOfficeReplies.htm"

$autoReplies = Get-Mailbox -ResultSize Unlimited | Get-MailboxAutoReplyConfiguration | Where-Object { $_.AutoReplyState –eq "scheduled" } | select @{Name="User";Expression={$_.identity.Name}}, ExternalMessage, InternalMessage
"<html><head><title>Auto Replies</title><style>" | Out-File -filepath $OutputFile 
"table { border-collapse: collapse; border: 1px solid black; }" | Out-File -filepath $OutputFile -Append
"td { border: 1px solid black; vertical-align: top; }" | Out-File -filepath $OutputFile -Append
"</style></head><body><table>" | Out-File -filepath $OutputFile -Append
"<tr><th>User</th><th>External Message</th><th>Internal Message</th></tr>" | Out-File -filepath $OutputFile -Append

foreach ($autoReply in $autoReplies) {
    "<tr><td>$($autoReply.User)</td><td>$($autoReply.ExternalMessage)</td><td>$($autoReply.InternalMessage)</td>" | Out-File -filepath $OutputFile -Append
}

"</table></body></html>" | Out-File -filepath $OutputFile -Append
Categories: PowerShell
  1. Guy M
    23rd February, 2017 at 01:50

    I found I needded to change the following line
    $_.AutoReplyState –eq “scheduled”
    to
    $_.AutoReplyState –eq “enabled” -or $_.AutoReplyState –eq “scheduled”

    to get everything. Otherwise you’re only catching those staff who have scheduled a response and missing those who have simply enabled it.

  2. 24th February, 2017 at 09:20

    Good catch, Guy. The other AutoReplyState option is “disabled”, which would let you view Out Of Office messages that are not being sent at the moment (more than likely, old Out Of Office messages).

  1. No trackbacks yet.

Leave a comment