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:
[PSComputerName: ex2010.cloud.local]
[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 } } $returnCollection }
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
Hi,
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?
Thanks,
Andy
hello Andy
i have not had the same errors, but it is hard to help when you have not posted your code.
anyways, i would recommend using a “here string” as described here: http://blog.coretech.dk/jgs/sco-2012-best-practice-inserting-user-input-safely-into-run-net-script-activity/
if you still have problems, you can cast it as [string]
i have added the type cast to the function it self to make sure the input is converted to the correct format. thank you 🙂
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.
[…] A quick look on the internet, brought me to the following article: http://blog.coretech.dk/jgs/scorchestrator-2012-ps-function-for-parsing-the-result-of-the-run-exchan… […]