question

benw-6517 avatar image
0 Votes"
benw-6517 asked AndreasBaumgarten edited

Powershell and Published Data Orchestrator 2016

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

msc-orchestrator
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered AndreasBaumgarten edited

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered

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





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

benw-6517 avatar image
0 Votes"
benw-6517 answered

Thanks for the feedback.

Yes I put in CCMUpdate and not $CCMUpdate.

41973-capture.jpg


This is what is being returned for that variable in Runbook Tester

41856-capture2.jpg



capture.jpg (19.2 KiB)
capture2.jpg (41.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLaude avatar image
1 Vote"
LeonLaude answered LeonLaude edited

Hi @benw-6517,

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

benw-6517 avatar image
0 Votes"
benw-6517 answered AndreasBaumgarten commented

Thank you both. Andreas your solution worked perfectly!

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You are welcome. And thanks for the feedback.


Kind regards
Andreas Baumgarten

0 Votes 0 ·