SCO 2012: PS Function for parsing the result of the “Run Exchange Management Shell Cmdlet” Activity


If you are using the Exchange Admin Integration Pack. You might have tried to use the run exchange shell cmdlet” activity and disocvered that the result is kind special in formatting.


Your result will look similar to this:

[RunspaceId: f30b4063-2b50-4609-9f84-91a480ac4bea]
[Database: Mailbox Database 1872261918]
[UseDatabaseRetentionDefaults: True]
[RetainDeletedItemsUntilBackup: False]

to help you , i have created a function for powershell that does it job:

function ConvertTo-ExchangeOutputCollection ([String] $inputText = @(throw "Error No Input Text supplied"))

    $returnCollection = @{}
    $keypairCollection = $inputText.Split("`n")
    foreach ($keypair in $keypairCollection)
        $trimmedKeyPair = $keypair.Trim().TrimStart("[").TrimEnd("]")
        $splitPosition = $trimmedKeyPair.IndexOf(":")
        $propertyName = $trimmedKeyPair.Substring(0,$splitPosition).Trim()
        $propteryValue = $trimmedKeyPair.Substring($splitPosition + 2).Trim()
        $returnCollection += @{ $propertyName =  $propteryValue }



use the function as shown here:

$result= ConvertTo-ExchangeOutputCollection $inputText
$database = $result.Database


The function created a key/pair collection containing all parts of the result, you then use the standard dot or [] syntax to get the value from the collection into a single simple string variable.

then get map the variable to published data as seen in this screenshot:



Update 15/05/2013: added [String] in parameter to make sure the input is in the right format. Thank you for reminding me Andy

Comments (5):

  1. Andy says:


    Thanks for the function but whenever I try to use it I get the following error:

    Method invocation failed because [System.Collections.ArrayList+ArrayListEnumeratorSimple] doesn’t contain a method named ‘Split’.

    I’m using a Powershell .net activity where I’m setting the output from the Exchange command (in this case get-mailboxpermission) to a variable then calling your function against that variable. My understanding is the problem is that the variable is not of a type that has a split method. I’ve tried prefixing the variable with [char] but it says it’s can’t convert the object. How should I be creating my variable using the output from the previous activities Exchange command to get it of an appropriate type?


  2. Vincent Leasum says:

    Hi, I really need to get this function working…. I’m learning powershell and Orchestrator, but I confess that I don’t understand how to use this function. could you post a screen shot of the whole runbook and pointing out where to use the function, how to invoke it, etc???

    thanks in advance.

Leave a Reply