Powershell script to import message classifications

By | May 28, 2012

If you are in a cross-forest mailbox migration scenario and use Exchange message classifications, this script might be useful to you.  If you plan to have the same message classifications in the target Exchange Organisation then you will want the classification IDs to match.  Without this, there is potential for the classification on migrated mail items not to be recognised.  For example, if you forward or reply to a migrated message and do not change the classification, then the classification will match the source Exchange Organisation and will not be recognised (even if the names match).  To avoid this scenario it is important to ensure that the classification IDs are the same in the source and target environment.

The first step is to export the message classifications in the source Exchange Organisation using the Export-OutlookClassification.ps1 in the \Scripts folder in the Exchange installation path.  This creates an XML file for you to use for the import.  Once you have the file, copy it to the target Exchange Organisation and run the script below.

#########################################################
#
# Name: Import-MessageClassification.ps1
# Author: Tony Murray
# Version: 0.1
# Date: 17 May 2012
# Comment:
# PowerShell script to import Exchange 2010 message
# classifications created in one forest to another forest.
#
# Uses xml file created from the
# Export-OutlookClassification.ps1 script in the source
# forest
#
# This method preserves the ClassificationID, which can
# be beneficial in cross-forest migration scenarios
#
##########################################################

$classfile = "C:\xml\Classifications_E2010.xml"
$mcs = Get-Content $classfile

foreach ($mc in $mcs.classifications.classification) {
    $name = $mc.name
    $dname = $mc.description
    $clid = $mc.guid
    New-MessageClassification -Name $name -DisplayName $dname `
    -ClassificationID $clid -SenderDescription $name

    # Tidy up variables used in foreach loop
    Clear-Variable -ErrorAction SilentlyContinue -Name mc
    Clear-Variable -ErrorAction SilentlyContinue -Name name
    Clear-Variable -ErrorAction SilentlyContinue -Name dname
    Clear-Variable -ErrorAction SilentlyContinue -Name clid
} # end foreach

# Tidy up global variables
Clear-Variable -ErrorAction SilentlyContinue -Name classfile
Clear-Variable -ErrorAction SilentlyContinue -Name mcs

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.