Setup an Out Of Office text reply for disabled AD account

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
bareedaa
Posts: 5
Joined: Mon May 20, 2013 12:55 pm

Setup an Out Of Office text reply for disabled AD account

Post by bareedaa » Mon May 20, 2013 1:03 pm

I would like to Setup auto an Out Of Office text reply for disabled active directory account(whenever the employee is terminated)using powershell. I need to have auto reply whenever the user account/mailbox user with in active directory is disabled.
I have the following script to automate but it is not working. Please help:

foreach($_ in (Get-ADUser -SearchBase "$_.recipienttypedetails -eq "usermailbox" -Filter {Enabled -eq $false})){
Set-MailboxAutoReplyConfiguration -Identity $_.DistinguishedName -AutoReplyState Enabled
-ExternalAudience All -InternalMessage "Your message to internal users" -ExternalMessage "Your message to external users" }

jvierra
Posts: 14018
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Setup an Out Of Office text reply for disabled AD accoun

Post by jvierra » Mon May 20, 2013 2:09 pm

You seem to be a little lost with the use of PowerShell syntax.

This might help a bit:
PowerShell Code
Double-click the code block to select all.
Get-ADUser  -Filter {Enabled -eq $false}  -Searchbase 'OU=MyOU,Dc-domain,DC=com' |
     ForEach{
          Set-MailboxAutoReplyConfiguration -Identity $_ `
                                            -AutoReplyState Enabled `
                                            -ExternalAudience All `
                                            -InternalMessage 'Your message to internal users' `
                                            -ExternalMessage 'Your message to external users'
     }

Locked