Powershell and Moving CCR Mailbox Server Instances Script…

In this article I would like to present an example script which is a little similar to the CCR Shutdown Script which I wrote about in this post: http://telnetport25.wordpress.com/2007/12/15/exchange-2007-ensuring-a-clean-ccr-node-shutdown/

You might be thinking – if you have already written about it, why re-hash it? – well the existing script in the post above seemed to exhibit some features with some readers of the blog that produced unpredictable results (see the comments on the post), it also required a certain amount of user intervention in order for it to work (e.g you needed to provide the names of your cluster nodes).

Additionally the script that I would like to present in this post is NOT a shutdown script per-se – it is a script that allows for new administrators of Exchange CCR clusters to safely move the Exchange resources between nodes by simply executing a batch file (or running the script via the Exchange Management Shell).

Design goals of the script:

Before I wrote the script that this post is based around I sat down an listed the design goals that I wished to achieve within the code:

  • No static variables – e.g. I did not wish for the administrator to have to manually add the Names of the cluster nodes, or indeed the Exchange cluster as variable into the script – I wished for these to be dynamically detected
  • The script needed to be able to determine which node within the cluster is running the active instance of Exchange
  • The script needed to be able to determine the passive instance within the cluster
  • The script needed to be able to make an choice about which node it should move the clustered instance to – irrespective of which node it is executed on


As well as the design goals I needed to create some assumption boundaries which formed that environmental parameters in which the script would be supported – these were as follows:

  • The script is designed to work on a TWO node CCR cluster

The script that I came up with is available for download below

ScriptMoveClusteredMailboxServerScript.ps1 [4KB]

As always when working with Powershell scripts (and indeed scripts that are on the larger side) I recommend that you download and install PowerGUI (http://www.powergui.org.uk). PowerGUI contains a brilliant syntax savvy script editor for Powershell which makes reading and debugging code much easier.

In order to execute the script you will need to set the Powershell execution model to “Remote Signed” this can be accomplished by opening the Exchange Management Shell and typing in Set-ExecutionPolicy RemoteSigned. You will also need to ensure that you have downloaded it to at least one node within your cluster.

In order to execute the script within the Exchange Management Shell navigate to the folder where you have downloaded it and then type in the following command: .\MoveClusteredMailboxServerScript.ps1 then press enter – see below:


Key aspect of the script:

This script has been predominately been given to you folks to see what you can accomplish with Powershell and Exchange management and I hope that you will use it and modify it to you own ends, however there are some aspects of the script which I would like to go through in a little more detail.

  • Determining the Exchange Cluster that the node belongs toIn order to complete this task I first needed to find out the name of the local machine (as this would be a node in a particular Exchange cluster) this is pretty straight forward in Powershell and is accomplished using the following:

$CompStat = Get-WmiObject win32_computersystem
$Localhst = $CompStat.Name

Where the $Localhst variable contains the NETBIOS name of the local machine – in order to determine the name of the Exchange cluster to which the node belongs to is accomplished via the following:

$Seed = Get-MailboxServer | Where-Object { $_.RedundantMachines -eq $Localhst }

Essentially the above code places the value of the Get-MailboxServer command where one of the redundant machines properties of the Mailbox server cmdlet contains the localhost name in the variable $Seed

  • Determining if the local machine is the Active or the Passive Node
    $MachineQ = Get-ClusteredMailboxServerStatus -identity $Seed.Name | Select OperationalMachines | Where-Object {$_.OperationalMachines -eq “$Localhst ”}

    This performs pretty much the same as above, but also takes into account if the local machine also owns the Quorum.

    In use if either the $Machine or $MachineQ variable is $NULL then the local machine is not the Active Node – and therefore in a two node SCR or CCR cluster must be the Active member (unless the cluster is down).

    $Machine = Get-ClusteredMailboxServerStatus -identity $Seed.Name | Select OperationalMachines | Where-Object {$_.OperationalMachines -eq “$Localhst ”}

    Essentially I have used the value that I have in the $Seed variable (which should be Mailbox Server name) with the Get-ClusteredMailboxServerStatus cmdlet.


    This is the part of the script that I am most proud of, I searched and searched for a simple way to get Powershell to return the NETBIOS name of the Active node within an Exchange cluster – it is not easy therefore I used the Get-ClusteredMailboxServerStatus cmdlet which returns many properties, however the one that I was most interested in was the “OperationalMachines” value – this give you the status and the role that each node has. If the local machine is represented as {Machine Name, } then it is currently the active node.You will also notice that I have another command which looks like the following:

I hope that you like to script it is the first of a few that I would like to present to you which might help make managing your Cluster’s a little easier. Bear in mind that this script could be modified to do far more than move clustered Exchange instances between nodes – if you come up with any cool ideas let me know.

Sharing is caring!:

4 thoughts to “Powershell and Moving CCR Mailbox Server Instances Script…”

  1. Hiya Martin, thank you for pointing this out to me – I have corrected the link and the download should now work.

  2. So I am looking for the original post because it had the correct procedure to actually shutdown a CCR environment cleanly. I just need that procedure. We are having to bring down our entire exchange environment and I have never been tasked with doing this and I want to make sure i do everything correctly. Thanks so much

Leave a Reply

Your e-mail address will not be published. Required fields are marked *