Resetting OOO for Exchange 2013 mailboxes

We have a requirement that the OOO for all mailboxes be reset every night at midnight to ensure that OOO notifications go out every day the person is out. I created this script and just wanted to get a second look at it to ensure it doesn’t impact production; it did work in my lab, but this place makes me paranoid. Coincidentally, the script someone else wrote broke the process, hence my hesitation.

I’m grabbing the autoreplystate for enabled or scheduled and putting into a variable, for future use. I tried a number of iterations using get-content, but it didn’t seem to work properly. So I just opted using a foreach going through the stored content of the $objmailbox variable.

Again, it seems to have worked in my lab, but I just need reassurance because everyone is now on alert for any oddities with OOO. Any feedback is appreciated:

$objMailbox = Get-Mailbox | Get-MailboxAutoReplyConfiguration | Where-Object { ($_.AutoReplyState -eq "enabled") -or ($_.AutoReplyState –eq “scheduled”)}
$objMailbox | Out-file C:\Support\Logs\ooo.log

$objMailbox | Set-MailboxAutoReplyConfiguration –AutoReplyState Disabled

foreach ($User in $objMailbox){

Set-MailboxAutoReplyConfiguration -Identity $User.MailboxOwnerID -AutoReplyState $User.AutoReplyState -StartTime $User.StartTime -EndTime $User.EndTime -InternalMessage $User.InternalMessage -ExternalMessage $User.ExternalMessage -ExternalAudience All

}

Chuck

Wow. It amazes me the “requirements” some companies come up with!

If it works in your lab, at some point you’ll just have to take the plunge and try it in production. I’m not sure an Internet Q&A forum would necessarily ease my paranoia ;).

But, I’ll point out that you’re getting ALL of the mailboxes. I have no idea how large the environment is, but that could involve a lot of processing and memory for PowerShell, especially as you’re saving them in a variable. This might be an instance where using ForEach-Object is more efficient.

Get-Mailbox | 
Get-MailboxAutoReplyConfiguration | 
Where-Object { ($_.AutoReplyState -eq "enabled") -or ($_.AutoReplyState –eq “scheduled”)} |
ForEach-Object {
  Set-MailboxAutoReplyConfiguration -Identity $_.MailboxOwnerID -AutoReplyState $_.AutoReplyState -StartTime $_.StartTime -EndTime $_.EndTime -InternalMessage $_.InternalMessage -ExternalMessage $_.ExternalMessage -ExternalAudience All
}

That way, you’re not forcing the shell to cache thousands of mailboxes in an in-memory variable, but are instead letting it process them in a stream.

Also, the reason you ran into issues with Get-Content is, frankly, because text is a horrible storage mechanism for objects. If the goal was to cache everything out to a file on disk for some reason, Import/Export-CliXML would be a far superior approach. XML is a much better storage mechanism and can do a much better job of preserving the object’s structure. Text sucks for anything other than output intended to be human-consumable.

So, I mean, my only suggestions here relate to performance. You AREN’T “grabbing the auto reply state… and putting it into a variable,” you’re grabbing the entire mailbox object. With more than a few hundred of them, that’s going to put a potential performance burden both on the Exchange server and on PowerShell. So that’s one consideration I’ll offer. We’ll see what others offer.

ah, I see. I wasn’t really looking for performance, since it’s running at midnight and there are only 1800 mailboxes, but I get your point and have updated the script. I’m going to pull the trigger and keep my fingers crossed. You’re right, some requirements are unbelieveable and sometimes I just have to bite my lip and get creative.

Thanks Don!