Delete An Email From All Mailboxes – Exchange 2007

Ex-Mgmt-Shell

Another day, another user who decided to give away their username and password to a phishing email. Thankfully this time it happened on a Monday morning, the spammer was kind enough to send to my internal users, and even better sent a spam to our helpdesk email. In other words – they basically told me they were sending spam from one of our mailboxes.

I did the usual – disabled the account/changed the password, blocked the spam/phishing site, purged our (growing) mail queues. But this time I really wanted to get rid of the email. So…
Powershell (Exchange Management Shell) to the rescue. Continue reading “Delete An Email From All Mailboxes – Exchange 2007”

Script to Compare List of Email Addresses in Exchange

I was provided a list of email addresses of employees in a system that doesn’t interface with AD/Exchange and asked to validate those email addresses exist within our Exchange server. I figured the easiest way was to just script it (the list was close to 1000 people).  Total run time to compare the list was just a few seconds.

Here’s the (quite simplistic) script to accomplish the task.


$logFile = 'c:\scripts\IsAccountValid.log'

# Uncomment the entry below if not running from the EMS
# Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

# Import the email addresses from text file
$Import=Get-Content "c:\Scripts\emailaddresses.txt"

ForEach ($address in $import) {
     $valid = get-mailbox -an $address
          If ($valid) {
          "$address is Valid" >> $logFile
          } else {
          "$address is Not Valid" >> $logFile
          }
}

Exchange 2007 Mailbox Listing by OU


Here we go again … PowerShell for a GUI OS.

Today was one of those – we need this list of user names and email addresses but don’t include this set of users and this other set of users. Simple Right? Well, not so much because the users don’t have Departments specified in the account, and the OU structure looks like this:

Domain > AllStaff> Location > Users

So, here’s how I got this list:

Get-Mailbox -resultsize unlimited -OrganizationalUnit “AllStaff” | where {-not ($_.organizationalunit -eq “Domain/AllStaff/Location/Users”) -and -not ($_.organizationalunit -eq “Domain/AllStaff/Other_Location/Users”) } | select displayname,primarysmtpaddress |Export-CSV c:\temp\List.CSV

Handy No?