Showing posts with label exchange 2003. Show all posts
Showing posts with label exchange 2003. Show all posts

Saturday, 21 February 2009

Slides from MMMUG presentation

As promised to those who attended the MMMUG on Wednesday night my slides from that evening are available on my SkyDrive.

Enjoy.

Wednesday, 28 January 2009

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"
}
Else
{
}

#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 = $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
}
else
{
}

}
}

Sunday, 25 January 2009

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

Sunday, 11 January 2009

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

ExchangeServer1
ExchangeServer2
ExchangeServer3

you would now use something like

ExchangeServer1New
ExchangeServer2New
ExchangeServer3New

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.

homemdb
msexchhomeservername
homemta

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.

Monday, 5 January 2009

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.