Sunday 19 January 2014

PowerShell Text formatting for Out Of Office message

PowerShell allows you to embed special characters within the string. These special characters are denoted using escape sequences. Escape sequences begin with the back tick (`), the one next to number 1 key on your keyboard.

`b => Backspace
`r => Carriage return
`n => New line
`t => Tab

Alternatively, if you are using PowerShell ISE, you can use preformatted text variable beginning with @” and ending with “@. In order to make this work, @” has to be the last thing where you define your string variable and “@ has to be on the new line at the end of your text and the first thing on that line. Otherwise it won’t work.
For instance,

$OOFMsg = @”
Thanks for your email.
I am out of office at the moment and will get back to you upon my return.
Regards,
Naw
“@

To Enable the Out of Office message

Unfortunately, the text formatting from PowerShell doesn't work on Exchange Mailboxes. Instead you will have to use html tags to embed line break as below.

$OOFMsg = “Thanks for your email.<br><br>I am out of office at the moment and will get back to you upon my return. <br><br>Regards, <br><br>Naw”

Set-MailboxAutoReplyConfiguration “Naw Awn” –AutoReplyState enabled –ExternalAudience all –ExternalMessage $OOFMsg –InternalMessage $OOFMsg



Out of Office Message begins from tomorrow till the next 3 days

Set-MailboxAutoReplyConfiguration “Naw Awn” –AutoReplyState scheduled –StartTime (Get-Date –uformat “%d/%m/%y”(Get-Date).AddDays(1)) –EndTime (Get-Date –uformat “%d/%m/%y”(Get-Date).AddDays(4)) ExternalAudience all –ExternalMessage $OOFMsg –InternalMessage $OOFMsg

To disable the Out of Office message

Set-MailboxAutoReplyConfiguration “Naw Awn” –AutoReplyState disabled

1 comment:

  1. Trie dusing `n & `r in an auto reply: Set-MailboxAutoReplyConfiguration -Identity MailboxID -AutoReplyState Enabled -InternalMessage "Please note, this mailbox is not monitored.`r`nThank you" Didn't work. Instead I used: Set-MailboxAutoReplyConfiguration -Identity MailboxID -AutoReplyState Enabled -InternalMessage "Please note, this mailbox is not monitored.
    Thank you" Looks like it accepts standard html, < p >,
    , < a href> etc

    ReplyDelete