Delete a specific Email from a list of mailboxes
Exchange 2007 SP2. I have the commandlet syntax to delete an email based on the mailbox alias (logon name) and it works fine, but I would like to be able to script the command and pass a list of names to be applied. The command I use:
Get-Mailbox -Identity "<alias>" | Export-Mailbox -SubjectKeywords <unique subject keywords> -StartDate <date>"
What i have tried running from a .PS1 file, but is not working:
foreach ($Person in Import-Csv "Alias.csv") {
$username = "*$($Person.username)*"
Get-Mailbox -Identity $username | Export-Mailbox -SubjectKeywords <unique subject keywords> -StartDate <date>" EndDate <date>" DeleteContent confirm:$false
}
Am I way off target? When I run the PS1, it just starts going through all mailboxes. Any help would be appreciated.
TK
May 24th, 2012 2:10pm
too much work just do do import-csv. in your csv file just make sure the first entry is alias
import-csv c:\alias.csv |foreach {get-mailbox $_.alias |Export-Mailbox -SubjectKeywords <unique subject keywords> -StartDate <date>" EndDate <date>" DeleteContent confirm:$false}James Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2012 2:20pm
Works like a champ. Thanks.
May 24th, 2012 2:53pm