Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $NeedsRetentions = @()
- # Get Start Time for script timer
- $startDTM = (Get-Date)
- #Authenticate using cached credentials or re-prompt for credentials.
- if (Test-Path C:\temp\mycred.xml) {
- $UserCredential = Import-CliXML C:\temp\mycred.xml}
- else{
- Get-Credential | Export-CliXml C:\temp\mycred.xml
- $UserCredential = Import-CliXML C:\temp\mycred.xml}
- #Connect to Exchange Server
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://munprdcasht04.exchange.com/PowerShell/ -Authentication Kerberos -Credential $UserCredential
- Import-PSSession $Session
- #returns alias' for mailboxes where creation date is <= 7 days and
- #resides on "ABC" or "DEF" server and has no retention policy applied
- $NeedsRetentions = (Get-Mailbox -ResultSize Unlimited| Where-Object {
- ($_.WhenCreated –ge ((Get-Date).Adddays(-7))) -and
- (($_.ServerName -like "*munprdmbxa*") -or ($_.ServerName -like "*wauprdexa*")) -and
- ($_.retentionpolicy -ne "PurgeDeletedItemsFolder_60days")} |
- ft -auto alias)
- ForEach ($NeedsRetention in $NeedsRetentions){
- set-mailbox -Identity $NeedsRetention -RetentionPolicy "PurgeDeletedItemsFolder_60days"
- }
- # Get End Time
- $endDTM = (Get-Date)
- # Echo Time elapsed
- "Elapsed Time: $(($endDTM-$startDTM).totalseconds) seconds"
Add Comment
Please, Sign In to add comment