Powershell and Published Data Orchestrator 2016

ben 21 Reputation points
2020-11-23T17:41:35.763+00:00

I am using Orchestrator 2016 with the reg change to make it use powershell 5.
In Powershell ISE, I run this simple query for a remote box to check the status of Windows updates via WMI:

$CCMUpdate = get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate" -namespace "ROOT\ccm\ClientSDK" -ComputerName '*computername*'
if(@($CCMUpdate | where { $_.EvaluationState -eq '2' -or $_.EvaluationState -eq '3' -or $_.EvaluationState -eq '4' -or $_.EvaluationState -eq '5' -or $_.EvaluationState -eq '6' -or $_.EvaluationState -eq '7' -or $_.EvaluationState -eq '8' }).length -ne 0) { $true } else { $false }

In ISE it returns the True or False as I would like, however, running it through a .NET activity in Powershell it doesnt return the True or false. I have $CCMUpdate as the publishedData on the .NET Activity.

What am I missing?
Thanks

System Center Orchestrator
System Center Orchestrator
A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.
217 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 98,626 Reputation points MVP
    2020-11-23T21:07:09.42+00:00

    LeonLaude is right. Sorry I didn't noticed this earlier.

    You script stores the result of the WMI query in the variable $CCMupdate.
    Than the logic works on the content of the $CCMupdate variable and will end up with $true or $false

    You need to write the result in a variable, for instance '$result' and add this variable to the Published Data of the .Net Activity.

    Something like this (not tested):

     $CCMUpdate = get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate" -namespace "ROOT\ccm\ClientSDK" -ComputerName '*computername*'
     if(@($CCMUpdate | where { $_.EvaluationState -eq '2' -or $_.EvaluationState -eq '3' -or $_.EvaluationState -eq '4' -or $_.EvaluationState -eq '5' -or $_.EvaluationState -eq '6' -or $_.EvaluationState -eq '7' -or $_.EvaluationState -eq '8' }).length -ne 0) { $result = $true } else { $result = $false }
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 98,626 Reputation points MVP
    2020-11-23T17:57:27.72+00:00

    How did you publish the data from the PowerShell script/.Net Activity?

    If the variable in the PowerShell script is $CCMUpdate, on the "Published Data" tab of the .Net Activity it must be CCMUpdate (without the $!) in the Variable Name field.

    More details you can find here: https://www.concurrency.com/blog/w/publishing-data-from-a-net-script-activity-in-orch


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

  2. Leon Laude 85,686 Reputation points
    2020-11-23T20:59:18.533+00:00

    Hi anonymous user,

    I don't believe the Run .Net Script runbook activity will work like that, Orchestrator is will basically run and store the whole WMI query in your CCMUpdate variable, and the output that will be returned is the same as if you would simply write $CCMUpdate in a PowerShell window, which will be neither True or False.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Best regards,
    Leon

    1 person found this answer helpful.
    0 comments No comments

  3. ben 21 Reputation points
    2020-11-23T20:27:23.017+00:00

    Thanks for the feedback. Yes I put in CCMUpdate and not $CCMUpdate. ![41973-capture.jpg][1] This is what is being returned for that variable in Runbook Tester ![41856-capture2.jpg][2] [1]: /api/attachments/41973-capture.jpg?platform=QnA [2]: /api/attachments/41856-capture2.jpg?platform=QnA

    0 comments No comments

  4. ben 21 Reputation points
    2020-11-23T22:57:25.393+00:00

    Thank you both. Andreas your solution worked perfectly!