Exchange Tip: How to save your Exchange objects

If you are going to change mailbox properties by a script, you will need to be ready to roll back the change smoothly without delay. It means to have a recovery procedure.

Basically if you change any mailbox object (it can be applied to any PS object), you should save it before because of recovery or reporting purpose.

[PS] C:\> $mbx = Get-Mailbox "filip"

Well, we used variable $mbx to store object Get-Mailbox “filip”.

The variable contains fully-described object (properties, methods, values).

[PS] C:\> $mbx.EmailAddresses[0].Prefix.PrimaryPrefix 

The variable and its data is defined by each Windows PowerShell provider. It means that it is alive based on provider memory and related session.

So how can we save it permanetly? We would export the object from PowerShell into the disk.

Object can be described by many ways but xml is most suitable format for representing our data structures and ensures also fully-described view. (Import-Clixml, Export-Clixml)

[PS] C:\> Get-Mailbox "filip" | Export-Clixml -Encoding unicode -path "D:\filip.xml"

The size of D:\filip.xml is about 0.6 MB (for 5 mailbox objects it is 0.96 MB), do not count 0.6 MB per mailbox.

[PS] C:\>(Get-Item D:\filip.xml).Length / 1MB

We have saved the mailbox and we can change for example its email addresses or anything else.

[PS] C:\> Set-Mailbox "filip" -EmailAddresses ""

After that we can revert the email addresses by D:\filip.xml anytime.

[PS] C:\> $f = Import-Clixml -Path "D:\filip.xml"
[PS] C:\> Get-Mailbox "filip" | Set-Mailbox -EmailAddresses $f.EmailAddresses

Well, feel free to use us the same procedure for any mass change regarding to server or recipient configuration and save your nerves during recovery.


$mailboxes = get-mailbox -ResultSize unlimited 
$mailboxes | Export-Clixml -Encoding unicode -path "D:\mailboxes.xml"
$mailboxes | Set-Mailbox -EmailAddressPolicyEnabled $True


$mailboxes = Import-Clixml -Path "D:\mailboxes.xml"
foreach($mailbox in $mailboxes){
    Set-Mailbox -Identity $mailbox.Identity -EmailAddresses $mailbox.EmailAddresses -EmailAddressPolicyEnabled $mailbox.EmailAddressPolicyEnabled

Exchange Tip: Exchange Virtual Directory URLs

Here is a one-line cmdlet for gathering all Exchange Virtual Directory URLs:


Get-Command -Verb "Get" -Noun "*VirtualDirectory"|%{Invoke-Expression -Command "Get-ClientAccessServer | $_ -ADPropertiesOnly |select server,name,*ternalUrl"}|sort -Property server

6- 11- 2013 11-53-55