Additonal Scripts on Exchange 2010 SP2

As with most Microsoft Exchange Service Packs and some Update Rollups, Exchange Server SP2 introduces six new scripts that are useful to manage and monitor your Exchange organization.

All the canned Exchange scripts are located in the %ExchangeInstallPath%Scripts folder (normally, C:Program FilesMicrosoftExchange ServerV14Scripts). You can easily change to this folder within the Exchange Management Shell (EMS) using the command cd $exscripts. It looks dirty, but it’s not. 🙂

The six new(ish) Exchange Service Pack 2 scripts are:

  • ConvertOABVDir.ps1 – This script will convert the OAB virtual directory to an IIS web application, as well as create a new application pool called MSExchangeOabAppPool. Converting the OAB virtual directory is necessary to support different authentication methods like Kerberos and Certificate authentication. You need to execute this script on each Client Access Server. Ross Smith wrote about this script in his article, Recommendation: Enabling Kerberos Authentication for MAPI Clients.
  • ExPerfwiz.ps1

How to Export Exchange 2010 ActiveSync statistics for IOS Devices.

I was just searching for a script to export the Active sync user list for IOS and statistics. Steve goodman showed me the way…Click Here

Few Poweshell commands

HUB Transport Server


Get-Queue -server ‘servername’ (Check Queue on a Hub Server)

get-messagetrackinglog -resultsize unlimited -EventID “RECEIVE” -Recipients “” -sender “” -Server “XXXYYYPP123” -Start “7/27/2010 12:00:00 AM” -End “7/29/2010 11:59:00 PM”

(To track the messages in a hub server, edit the query as needed)

Mailbox Server


Get-MailboxDatabase -server cmsname -status | select name,mounted (To check the status (Mounted) of all mailbox database in a server)

Get-MailboxDatabase -server cmsname -status | select Name,Server,*backup*,Mounted (To check the last Backup of all mailbox database in a server)

Dismount-Database CMSNAME\CMSNAME-SG01 (Dismount a single database)

Get-MailboxDatabase -server cmsname | Dismount-Database (Dismount all the mailbox database in a server)



Get-StorageGroupCopyStatus -server cmsname (To check the replication status of all storage group in a server)

Test-ReplicationHealth (To check the replication health of a cluster)

Suspend-MailboxDatabaseCopy -Identity CMSname\CMSname-SG01 -SuspendComment “Maintenance on 001” (Pause the replication of a storage group)

Resume-MailboxDatabaseCopy -Identity cmsname\CMSname-SG01 (Resume the replication of a storage group, which was paused)

Restore-StorageGroupCopy CMSNAME\CMSNAME-SG01 (Ignore the consistency state and make database mountable, possible of data loss)

Update-StorageGroupCopy CMSNAME\CMSNAME-SG01 -DeleteExistingFiles (Reseed the replication which was failed)

Move-ClusteredMailboxServer -Identity ‘CMSNAME’ -MoveComment ‘Install Forefront on A node’ -TargetMachine ‘nodeb’

Troubleshooting Cluster Servers


1. Always use “Move-ClusteredMailboxServer” command to failover the server

2. Before failover the server, it is better to check whether the passive node is up to date.

Run “Get-StorageGroupCopyStatus” to see the target database is updated. The copy status should be Healthy and CopyQueueLength & ReplayQueueLength should be 0.

Do not failover the cluster if there is some value in CopyQueueLength or ReplayQueueLength unless it is really required. (Less value in CopyQueueLength & ReplayQueueLength is less data loss)

3. If the copy status failed first try “Resume-MailboxDatabaseCopy” then “Update-StorageGroupCopy” (Do not go for “Update-StorageGroupCopy” without seniours advise)

PowerShell V2 Download

If you are running Windows 7 or Windows Server 2008 R2, then you will have PowerShell installed by default. On Windows 7, both the PowerShell console and PowerShell ISE are installed by default. On Server 2008 R2, PowerShell console is installed by default, whilst the PowerShell ISE is a feature you can add using Server Manager. And of course, for any Server 2008 R2 core installations, you would need to add both the .NET Framework and PowerShell – virtually nothing extra gets added to Server Core!

For downlevel (aka older) versions of Windows, Microsoft has released a KB article which directs you to versions you can download. Go to the page where you can find PowerShell V2 for Windows XP, Vista, Server 2003 and Server 2008 (RTM) – in both 32-bit and 64-bit versions. Note that in Server 2008 RTM, PowerShell is not supported in Server Core.

In addition to PowerShell V2, the downloads also include the RTM version of Windows Remote Management (WinRM). WinRM is Microsoft’s implementation of the standards based WS-Management Protocol. WinRM is based on Simple Object Access Protocol (SOAP), and provides a firewall-friendly protocol enabling hardware and operating systems from different vendors to interoperate.

If you are are using an older OS, i.e. Windows 2000 or earlier, then there is no supported version of PowerShell for you. You can probably hack some or even most of PowerShell V2 into those older OSs. But things may not work – and it’s not ever going to be supported.

Powershell for Exchange Server

This article explains the features of the exchange management shell EMS. Unlike the previous version of the exchange, the exchange server 2007 has this new feature of accomplishing all the exchange related activity in the command shell. The PowerShell uses the cmdlets as a core technology. A cmdlet is a lightweight command that is used in the PowerShell and Exchange Management Shell environments. Within that environment, the PowerShell command interpreter (PS.exe) executes these cmdlets within the context of automation scripts. The .NET framework is the core package which executes the PowerShell. Nearly 350 exchange related cmdlets are available in the EMS. The EMS works in the back end of the exchange management console.

Uses of EMS:

1. EMS main usage is to perform the administrative functions such as Mailbox management, setting limits for users, Moving mailbox b/w servers, configuring the exchange related parameters, etc.
2. EMS also helps in generating the reports such as recipient details, messaging routing traffic, message size distributions, etc.

General Syntax of the PowerShell Commands:

#Verb-Noun format. The PowerShell commands are auto-tab complete.
Eg., Move-Mailbox, Get-Mailbox, etc.
The commands in the PowerShell can be chained using the pipe option.

Interpreting the PowerShell Commands:

In order to move the mailbox to other server,
In General, Move the Mailbox of the user Stephen to the Mailbox Store2. This can be put syntactically
#Move-Mailbox “Mcgrorty, Stephen” –Targetdatabase “Mailbox Store 2”

Help Option in the EMS:

1. #Get-Help command
2. #Get-Help Set-Mailbox –Parameter *quota*
3. #Get-Help -Role *Mailbox*
Eg, Get-mailboxpermission,Get-mailboxdatabase,etc.
4. #Get-Help -Role *Mailbox* | fl name, synopsis
5. #Get-Help -Component *Recipient*
Eg, Get-mailbox,get-mailboxstatistics,etc.
6. #Get-Help -Functionality *Server*
Eg, Get-mailboxserver,Get-sendconnector,etc.

Pipeline Option:

To move all mailbox in the server1 to the server2
#Get-Mailbox –server server1 | Move-Mailbox –targetdatabase “server2\Mailbox Store1”

To set the maximum send size attribute for the recipient “Andreo Nel”
#Get-Mailbox | where-object { $ –like “And*” } | Set-Mailbox –MaxSendSize 10mb

WhatIf and Confirm Option:

To move the mailbox with the name “sandy” to the server2. The –WhatIf parameter informs the administrator what action the script would take and the –Confirm parameter prompts for confirmation before taking action.

#Get-Mailbox | where-object { $ –like “sandy*” } | Move-Mailbox –targetdatabase “Server2\Mailbox Store1” –WhatIf

Sample Output:

What if: Performing operation “move-Mailbox” on Target “Move mailbox for:Administrator ( to Database: Mailbox Database 2,09014bc6-f977-4961-b4eb-8829fb13e5d6. The operation can take a long time and the mailbox will be inaccessible until the move is complete”.

#Get-Mailbox | where-object { $ –like “sandy*” } | Move-Mailbox –targetdatabase “Server2\Mailbox Store1” –Confirm

Sample Output:

Are you sure you want to perform this action? Performing operation “move-Mailbox” on Target “Move mailbox for: Administrator ( to Database: Mailbox Database 1,09014bc6-f977-4961-b4eb-8829fb13e5d6. The operation can take a long time and the mailbox will be inaccessible until the move is complete”. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”):

Some Important and Useful PowerShell Commands In exchange server 2007:

1. To create a new mail database in the first storage group on server2.
#New-MailboxDatabase –StorageGroup “SERVER2\First Storage Group” –name “Mailbox Store2”

2. To mount the above database,
#Mount-database “SERVER2\First Storage Group\Mailbox Store2”

3. To test the connectivity of the recipient mailbox and also to check the latency.

4. To get the list of mailbox with the maximum mailbox size,
#Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName SERVER1 | select-object MailboxDisplayName,TotalItems,Size | sort -descending “Size” | select-object -first 25

5. The above can also be viewed in the HTML format and also can be directed to some file. This makes it portable.
#Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName SERVER1 | select-object MailboxDisplayName,TotalItems,Size | sort -descending “Size” | select-object -first 25 | ConvertTo-html -title “Top 25 Largest Mailboxes on SERVER1” > “D:\Stats\25 Largest Mailboxes.html”

6. To get the events in the application log with the source starting with the word “Exchange” ,
#get-eventlog Application | where {$_.Source -ilike “Exchange*”} | export-csv c:\events.csv

7. To get the information of particular user mailbox
# Get-Mailbox –Identity “Rudi Kutz”
#Get-Mailbox “Rudi Kutz”

8. To get the list of exchange servers in the organization,
#Get-ExchangeServer -Domain
#Get-ExchangeServer –Status

9. To get the mailbox database details,
# Get-MailboxDatabase -Server Server
#Get-MailboxDatabase -StorageGroup StorageGroup

10. To set the quota limit parameter for particular database,
# Set-MailboxDatabase -Identity MailboxDatabase -IssueWarningQuota 500MB

11. To set the user’s mailbox properties like external Email Email address value,
# Set-MailUser -Identity user2 -ExternalEmailAddress

12. To get all the records which matching the namespace “logu”, it check in all the possible recipients like user mailbox, contacts, etc.
# Get-Recipient -Anr “logu”

13. To Enable/Disable the user,
# Disable-MailUser -Identity user2
# Enable-Mailbox -Identity company\user1 -Database MailboxDatabase

14. To get the mailbox statistics of the database,
# Get-MailboxStatistics -Database MailboxDatabase
#Get-MailboxStatistics -Server Server

15. To give full access permission for the user1 on the mailbox user2,
#Add-MailboxPermission user2 -User user1 -AccessRights FullAccess

16. The same case if it is a linked mailbox (external mail account which has mailbox in this server),
#Add-MailboxPermission user2 -user CODE1\user1 -AccessRights:FullAccess,ExternalAccount