I am trying to write a script that enables online archive and sets a retention policy for users in two mailbox databases and removes online archives and sets a different retention policy for users in another mailbox database.
I have worked out the commands that I need, I just need some help putting them all together into a script and calling that script from a scheduled task. I have tested running them from EMS and they work great. I would like some pointers on how to call them in EMS environment instead of regular powershell if possible. If I run them from Powershell ISE or just powershell with the exchange snapins added, I get a bunch of warnings Ex. WARNING: The cmdlet extension agent with the index 3 has thrown an exception in OnComplete()
Here is what I have so far.
Load Exchange Modules/PSSnapins
Get-PSSnapin -Registered | Add-PSSnapin
Set Retention Policy based on Mailbox Database
Get-Mailbox -ResultSize unlimited -Database Tier1 -Filter {(Name -NotLike "DiscoverySearch*")} | Set-Mailbox -RetentionPolicy "6 Month Archive"
Get-Mailbox -ResultSize unlimited -Database Tier2 -Filter {(Name -NotLike "DiscoverySearch*")} | Set-Mailbox -RetentionPolicy "6 Month Archive"
Get-Mailbox -ResultSize unlimited -Database Tier3 -Filter {(Name -NotLike "DiscoverySearch*")} | Set-Mailbox -RetentionPolicy "6 Month Delete"
Enable/Disable Online Archive based on Mailbox Database
Get-Mailbox -ResultSize unlimited -Database Tier1 -Filter {(Name -NotLike "DiscoverySearch*")} | Enable-Mailbox -Archive -ArchiveDatabase Tier1
Get-Mailbox -ResultSize unlimited -Database Tier2 -Filter {(Name -NotLike "DiscoverySearch*")} | Enable-Mailbox -Archive -ArchiveDatabase Tier2
Get-Mailbox -ResultSize unlimited -Database Tier3 | Disable-Mailbox -Archive
Any assistance would be greatly appreciated. Thanks gentlemen!
ASKER
Is there anything i need to do with my commands to in the .ps1 script or just place them 1 per line?