Tag Archives: exchange 2003

Updated Exchange 2003 PowerGUI PowerPack

Since PowerGUI version 1.8 there have been some great enhancements in PowerPack management. So I finally got round to updating the Exchange 2003 PowerPack and publishing it in the new format. One of the best new features is the ability to update the PowerPack from the application – previously you had to manually download the new version, remove the old one then import the updated copy.

Within the PowerPack Management Dialogue Box you can see the current version of your PowerPack:


If you click on the Check for Update button PowerGUI will check for an updated version of the PowerPack whether it be on the PowerGUI website or on a locally availbale file share. If there is a new version then you are prompted to download it and upgrade:


Answer Yes and the updated PowerPack will begin to download:


Once complete you will see it has been updated to the new version:


By default PowerGUI will check for updated PowerPacks everytime you open it:


If you are a PowerPack creator then you can specify the location of your PowerPack. PowerGUI will automatically update the version number for you whenever you save any changes to it:


Its as simple as that!

As an extra bonus I have added a new script node to the PowerPack which examines the event log of an Exchange 2003 server and reports the whitespace in each database for you.


Exchange 2003 / WMI / PowerShell article over at http://www.simple-talk.com/

So I got asked to write an article for the http://www.simple-talk.com/ website, a well known online technical journal and community hub around SQL and .NET technologies. They’ve recently been branching out into Exchange as well hence they reason they were looking for some Exchange based articles.

The article I have written for them is based around a presentation I have made around some user groups a few times now, i.e. using PowerShell and WMI to manage Exchange 2003. I really enjoyed the process of transferring the content into a written article and hopefully I may get the opportunity to write some more so please check it out.

You can also take advantage of a free Sybex Best Of Exchange 2007 Server ebook by signing up for their Exchange newsletter.

Using Powershell to Find Free Space in Exchange 2003 databases: Updated

Back in January I posted about how to find free space in Exchange 2003 databases using Powershell.  Not long after this we changed our online maintenance schedules resulting in each database not having maintenance every day. The original script was based on the assumption of maintenance happening every day and there being events in the application log for every database in the last 24 hours.

Consequently I have had to adjust the script so that it would look back a few days to ensure there are logs for each database. This then created an interesting problem because it meant that sometimes you would get back more than one result per database and so obviously you would only want to keep the most recent result.

For example you would get results like the below:

ServerName,MailboxStore,”Free Space (MB)”,”Time Written”

If I used:

$myCol | Sort-Object Servername,MailboxStore -unique

it would produce results with only one entry per mailbox store, but it would always choose the most recent result. So I posted my issue to the PowerShell newsgroup and MVP Marco Shaw very kindly helped me work through it. The end result was this:

$hash[email protected]{}
$myCol | Sort-Object @{Expression="Servername";Descending=$false},@{Expression="MailboxStore";Descending=$false},@{Expression="Time Written";Descending=$true} | Foreach-Object {if($hash[$_.mailboxstore] -eq $null){$hash[$_.mailboxstore]=$_}}
Marco explains below how this works:
“Imagine the following simple data:
PS C:\Users\Marco> gc data.csv
In your case, you have event log entries.  Now, with the above code, you determine you want to only retrieve the first IP listed for each server.  There’s several ways to accomplish this, but with my hash table approach…

ipcsv data.csv|%{if($hash[$_.server] -eq $null){$hash[$_.server]=$_}}

So, I create $hash as a hashtable variable.

I use a foreach-object to look at each object in the collection.  Looking at each object’s server property, I get the current value of the property ($_.server).  I use that as the key for my name/value pair in the hashtable.
Basically, if we take the first line of the input data where $_.server=”server1″, I take that property, and check if the hashtable already has this name if($hash[$_.server] -eq $null).  If that is true, this is the first occurence of the value “server1”, so I create that hash key with that name and pass $_ as the value.
When I hit line #2 in the input data, and check $hash[$_.server] again (or $hash[“server1”]), I see that name already exists, so I skip it.
Then onto line #3, where $_.server is now “server2”.
So from the above, I make sure that for each serverX, I get only the first IP address in the list.

This is similar to your scenario where you only want the first occurence per mailboxstore.”
The resulting updated script is below. Note I also updated it somewhat on the original based on a useful technique illustrated in another posting.
$ExchServer = 'Server1','Server2'

#Get the time 3 days ago in the right format for WMI query
$WmidtQueryDT = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime([DateTime]::Now.AddDays(-3))

$myCol = @()
foreach ($Server in $ExchServer){

    #Perform WMI query of Event 1221 in Application log in the last day
    $eventid = Get-WmiObject -computer $Server -query ("Select * from Win32_NTLogEvent Where Logfile='Application' and Eventcode = '1221' and TimeWritten >='" + $WmidtQueryDT + "'")

    foreach ($event in $eventid){

        #Get the name of the Mailbox Store
        $MBXStoreLocationStart = $event.Message.IndexOf("Storage Group") + 16
        $MBXStoreLocationFinish = $event.Message.IndexOf("has") - 2
        $MBXStoreLocation = $event.Message.SubString($MBXStoreLocationStart, $MBXStoreLocationFinish - $MBXStoreLocationStart)

        #Get the free space figure
        $MBLocationStart = $event.Message.IndexOf("has") + 4
        $MBLocationFinish = $event.Message.IndexOf("megabytes") - 1
        $MBLocation = $event.Message.SubString($MBLocationStart, $MBLocationFinish - $MBLocationStart)

        #Store the data in $myCol
        $MYInfo = “” | select-Object ServerName,MailboxStore,'Free Space (MB)','Time Written'
        $MYInfo.ServerName = $event.ComputerName
        $MYInfo.MailboxStore = $MBXStoreLocation
        $MYInfo.'Free Space (MB)' = $MBLocation
        $MYInfo.'Time Written' = $event.TimeWritten
        $myCol += $MYInfo


$hash[email protected]{}
$myCol | Sort-Object @{Expression="Servername";Descending=$false},@{Expression="MailboxStore";Descending=$false},@{Expression="Time Written";Descending=$true} |Foreach-Object {if($hash[$_.mailboxstore] -eq $null){$hash[$_.mailboxstore]=$_}}
$hash.values | Sort-Object Servername,MailboxStore | Export-Csv AllExchangeWhiteSpace.csv -NoTypeInformation

Using Powershell to Find Free Space in Exchange 2003 databases

One regular task for Exchange admins can be reclaiming free space within Exchange mailbox stores either after a large amount of data has been removed or just a significant amount has built up over time for various reasons. For those of you who don’t know, to reclaim the space the mailbox store has to be taken offline and the database defragged to get the space back on the disk.

Finding good candidates for defragging especially in a large environment with multiple databases and Exchange servers can be a pretty tedious task. Exchange records an entry in the Application Event Log (Event ID 1221) after online maintenance has taken place which tells you how much free space is in the database – this means trawling through the event logs on each server and recording which databases you think are worth defragging. So naturally I wrote a Powershell script to save wasting time on this task!

Using WMI the script queries the Application log on each of the Exchange servers you choose, looking for 1221 events in the last day. It sucks out the name of the mailbox store and the amount of free space in the database from the message field of the event and if the free space is greater than a particular figure (in the example below 3GB) adds the info to a csv file.

You could obviously change the figure to meet your needs and also if you remove the if statement you could get it to report on every database so you have a report of free space across all databases.

Tip: If you have clustered mailbox servers then you only need to point the script at one of the servers in the cluster since it will contain all of the event log entries for each server in the cluster.

#Check to see if csv exists and if so remove it
If (Test-Path FreeSpaceGreaterThan1GB.csv)
Remove-Item FreeSpaceGreaterThan1GB.csv

#Set the columns for the csv file
$rows = Servername, + Mailbox Store, + Free Space (MB),
Add-Content FreeSpaceGreaterThan1GB.csv $rows

$ExchServer = server1,server2
foreach ($Server in $ExchServer){

#Get the time 1 day ago in the right format for WMI query
$WmidtQueryDT = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime([DateTime]::Now.AddDays(-1))
#Perform WMI query of Event 1221 in Application log in the last day
$1221 = Get-WmiObject -computer $ExchServer -query (Select * from Win32_NTLogEvent Where Logfile=’Application’ and Eventcode = ‘1221’ and TimeWritten >=’ + $WmidtQueryDT + )

foreach ($event in $1221){

#Get the name of the Mailbox Store
$MBXStoreLocationStart =<
span style=”color:rgb(0,0,0);”> $event.Message.IndexOf(Storage Group) + 16
$MBXStoreLocationFinish = $event.Message.IndexOf(has) 2
$MBXStoreLocation = $event.Message.SubString($MBXStoreLocationStart, $MBXStoreLocationFinish $MBXStoreLocationStart)

#Get the free space figure and convert it to an integer
$MBLocationStart = $event.Message.IndexOf(has) + 4
$MBLocationFinish = $event.Message.IndexOf(megabytes) 1
$MBLocation = $event.Message.SubString($MBLocationStart, $MBLocationFinish $MBLocationStart)
$result = [int]$MBLocation

$ComputerName = $event.ComputerName

#If free space > 3GB, add the details to the csv file
if ($result -ge 3072){

$rowline = $ComputerName, + $MBXStoreLocation, + $MBLocation,
Add-Content FreeSpaceGreaterThan1GB.csv $rowline


Presenting at MM&M User Group UK – Wednesday 18th February

So I was lucky enough to receive an invite from Nathan Winters who runs the MM&M User Group UK (aka Exchange) to present at their next meeting on Wednesday 18th February at Microsoft in London.

It will be an evening around using Powershell to manage Exchange, the agenda is as below:

18:15 – 18:40 Arrival

18:40 – 18:45 Introduction to speakers and the aims of the group

18:45 – 19:30 1st session; Jonathan Medd, Introduction to PowerShell and Using PowerShell to manage Exchange 2003!

19:30 – 19:50 Food!

19:50 – 20:45 2nd session; Will Rawlings, Causing no harm with PowerShell, and using PowerShell on a large Exchange environment

20:45 – 21:00 Summing up and suggestions for future meetings.

21:00 The End!

If you want to attend you can sign up here http://www.mmmug.co.uk/forums/thread/26352.aspx

Modifying AD accounts with Powershell after an Exchange 2003 dial-tone restore

Recently I’ve been testing out some different disaster recovery scenarios for Exchange 2003, one of which involved a dial-tone method – i.e. create some new mailbox servers with blank databases to get users up and running quickly and then merge the restored data back in later. One of the types of dial tone method we used was to create new server names rather than re-use existing Exchange server names.

So for example to re-create a four node (3 active, 1 passive) cluster with new names, instead of


you would now use something like


Then you would need to amend the AD user accounts for users on those Exchange Servers to point to the new locations – the following properties need to be changed.


None of these properties can be changed through ADUC, you would need to use ADSIEdit if you wanted to use a GUI. Of course those smart people among you would choose to user Powershell anyway.

So naturally I turned to my trusty friend the Quest AD cmdlets to help me out.

First of all we get all the users who have a mailbox based on one of the original servers; depending on your naming convention you may need to adjust this filter to make sure you are matching the correct people. The three properties mentioned are not returned by default from Get-QADUser so we have to specify them.

We then loop through each user and using the Switch statement if we match ExchangeServer1, 2 or 3 we amend the text of each variable to be the new Exchange servername (note: homemta will be the same for all of these users) and then user the Set-QADUser cmdlet to change these properties on the account.

$users = Get-QADUser -ldapFilter '(msExchHomeServerName=*ExchangeServer*)' -IncludedProperties homemdb,msexchhomeservername,homemta -sizelimit 0

foreach($user in $users){

$homemdb = $user.homemdb$msexchhomeservername = $user.msexchhomeservername$newhomemta = 'CN=Microsoft MTA,CN=ExchangeServer1New,CN=Servers,CN=Exchange,CN=Administrative Groups,CN=Springfield,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=springfield,DC=local'

switch -wildcard ($homemdb)

{"*ExchangeServer1*" {$newhomemdblocation = $homemdb.replace("ExchangeServer1","ExchangeServer1New"); $newmsexchhomeservername = $msexchhomeservername.replace("ExchangeServer1","ExchangeServer1New");  Set-QADUser $user -objectAttributes @{homemdb=$newhomemdblocation;msexchhomeservername=$newmsexchhomeservername;homemta=$newhomemta}; break}"*ExchangeServer2*" {$newhomemdblocation = $homemdb.replace("ExchangeServer2","ExchangeServer2New"); $newmsexchhomeservername = $msexchhomeservername.replace("ExchangeServer2","ExchangeServer2New");  Set-QADUser $user -objectAttributes @{homemdb=$newhomemdblocation;msexchhomeservername=$newmsexchhomeservername;homemta=$newhomemta}; break}"*ExchangeServer3*" {$newhomemdblocation = $homemdb.replace("ExchangeServer3","ExchangeServer3New"); $newmsexchhomeservername = $msexchhomeservername.replace("ExchangeServer3","ExchangeServer3New");  Set-QADUser $user -objectAttributes @{homemdb=$newhomemdblocation;msexchhomeservername=$newmsexchhomeservername;homemta=$newhomemta}; break}default {"Nothing for this user"}}


I was also interested to see the resulting performance of this script and was pleasantly surprised to see it change 6000+ accounts in only 10 mins.

A sidenote to this method is that you won’t actually see the mailboxes appear in Exchange System Manager until either they receive an email or a user logs on to them. To prove that this method had worked I created a quick Distribution Group, used the below one-liner to populate it with all of the above users and then sent an email to this group.

Get-QADUser -ldapFilter '(msExchHomeServerName=*ExchangeServer*)' -sizelimit 0 | Add-QADGroupMember TestGroup

There are of course many different ways to carry out Exchange DR, but this proved a useful exercise.

PowerGUI webcast – Exchange 2003 Powerpack demo

I was recently invited to record a webcast by the Product Manager at Quest for PowerGUI, Darin Pendergraft, demoing the Exchange 2003 Powerpack I made for PowerGUI.

They came up with the idea to make some videos / webcasts giving some community members the opportunity to show what PowerGUI can do. A lot of people primarily use it only as a script editor, but the management console side of things is brilliant once you get into it – hopefully these examples will help inspire more people to make some powerpacks.

I had a lot of fun recording the interview, it was funny to be on the other end of the questions for once, normally I’m asking them for the Get-Scripting podcast.

It runs for about 15 – 20 mins, I hope you enjoy it.