Set the Firstname attribute to equal the Name (cn) attribute.

get-qaduser -searchroot “ou=people,ou=hope,dc=fun,dc=local” |foreach { set-qaduser $_  -firstname ($}


Setting the SMTP address when an email policy won’t do the trick

I’m migrating a bunch of users from one domain to another. The client promised the end users that the first part of their email shall remain the same, only the domain changes. So, for example, if Bob Jones email address is , the default email policy would create, but the client promised the end users that it would be

Input file that looks like this:


The script unchecks the “Automatically update e-mail addresses based on e-mail address policy”, and then it assigns a new primary smtp address.

$CSV = Import-CSV C:\temp\first50-smtp.csv
foreach ($entry in $Csv) {
Set-mailbox -identity $entry.samaccountname -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $entry.emailaddress

Check for existing user in active directory

This powershell script below allows me to take
an input file that looks like this (input-users.csv)


and make an output file that will look like this (out.csv)


The client I was working at did NOT have any windows 2008 dcs, so i could not use the command get-aduser, instead I installed the quest tools and I am using get-qaduser

Basically, this script give me a yes or no to the question “does the user (samaccount) exist?” Special thanks to Raymond for helping me with the output (I’m still new at powershell)

$users = Import-Csv c:\scripts\input-users.csv
foreach ($user in $users)
 if (get-qaduser -SamAccountName $user.SamAccountName)
 "$($user.SamAccountName),yes" | out-file out.csv -append
 #NOT Found...
 "$($user.SamAccountName),no"| out-file out.csv -append


$users = Import-Csv c:\temp\ALLSMTP1.csv
 foreach ($user in $users)
 if (get-qaduser -email $user.SMTPaddress)
 "$($user.SMTPaddress),yes" | out-file smtp-yes.csv -append
 #NOT Found...
 "$($user.SMTPaddress),$($user.samaccountname),no"| out-file smtp-no.csv -append

Import Export IP list on Allowed Relay Receive Connector

If you are migrating from Exchange 2003 to 2010, when you export the list of allowed relay devices, following this article the output will typically be in this format:

Name the file IPList.txt
So, with the script below, you can import the list of ip addresses on your receive connector

$RecvConn = Get-ReceiveConnector "Ex2010\AllowedRelay"
Get-Content .\IPList.txt | foreach {$RecvConn.RemoteIPRanges += "$_"}
Set-ReceiveConnector "Relay Connector" -RemoteIPRanges $RecvConn.RemoteIPRanges

When you are migrating from Exchange 2007 to 2010, we use powershell command to export the list, and a powershell script to import

Here is the powershell command to export the list. Change the exchange 2007\allowedrelay part to be the correct server\receive connector name.

(Get-ReceiveConnector "exchange2007\allowedrelay").RemoteIPRanges | select Lowerbound,Upperbound,RangeFormat | sort-object Lowerbound| export-csv c:\rc.txt –NoTypeInformation

Use this script to import it onto the exchange 2010, change the second line to be the correct exchange 2010 server name \ receive connector name

$csv = "c:\rc.txt"
$rc = "EX2010\RelayConnector"
$impcsv = import-csv $csv
foreach($line in $impcsv)
$ipAdd = $line.LowerBound
$conn = Get-ReceiveConnector $rc
$conn.RemoteIPRanges += $ipAdd
Set-ReceiveConnector $rc -RemoteIPRanges $Conn.RemoteIPRanges

Set homeDirectory attribute to users from input csv file

The non-standard home directory path will be set on the user account in active directory using the input file called home-dir-path.csv which contains two fields.

The Microsoft Logon name, the samAccount attribute, followed by the Home Directory Path in UNC format, which is the homeDirectory attribute.

The tool used to set the attribute is Quest powershell with the Set-QADUser

For a single user, it would be executed as such:

Set-QADUser b125013 -HomeDirectory \\server\vol1\user\b125013

I made a script called SetHomeDir.ps1, that has the following code

Import-Csv home-dir-path.csv | ForEach-Object {

Set-QADUser $_.SamAccountName –HomeDirectory $_.HomeDirectory


Make sure the input csv file has the following line for the first row:

SamAccountName, HomeDirectory

Mailbox Stats Mailed Exchange 2010

The goal of this article is to create a mailbox.txt file that contains mailbox statistics about your exchange users AND to have it mailed to you everyday at say, 5:00pm.

This article is specific for Exchange 2010, but it can be used on 2007, just modify the path to Exchange installation folder by removing the “v14” folder.

You will be creating two files, both reside in the “bin” folder of exchange, by that I mean for a standard installation of Exchange 2010, it would be the following folder:
C:\Program Files\Microsoft\Exchange Server\v14\bin

First, create a file called SendStats.ps1 that has the following two lines of code and three comment lines (which begin with ###)

###Send mailbox statistics script###
###Get the stats and store in a text file called mailboxes.txt###
Get-MailboxStatistics -database "Exchange Mailbox Database"| Sort-Object DisplayName | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount > mailboxes.txt

###Create the mail message and add the mailboxes.txt text file as an attachment###
Send-MailMessage –From –To –Subject "Mailbox Size Report" –Body "Attached is the current list of mailbox sizes." -Attachment "Mailboxes.txt" –SmtpServer localhost

You will need to modify the -database “Exchange Mailbox Database” to the actual name of your database and you will need to modify the from and to addresses to a valid email address for your system.
I found that exchange 2010 likes ‘localhost’, but exchange 2007 likes the dns name of the server itself, as in ‘server1.addomain.local’

Then, create another file called MBStats.bat which contains two lines of code:

cd "C:\Program Files\Microsoft\Exchange Server\v14\Bin"
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\v14\Bin\ExShell.psc1" -Command "sendstats.ps1"

The nice thing about this batch file is that it easily allows you to make the scheduled task without a lot of command line arguments  (and testing the script from a cmd prompt is easy too)

Like I said above, both of these files are stored in the “bin” folder of exchange.

Finally, go into the Scheduled Tasks of Windows 2008 R2 and create a scheduled task to run every day at 5pm, whether user is logged on or not.

You can just type in the batch file name, you won’t need to point to the entire path location because the Exchange “bin” folder is already in the PATH variable.