opalis: properly retrieving published data from powershell scripts

i’ve been tooling around with opalis in my lab for the past week or so.  i’ve been working on this pet project when i stumbled on something.

  1. wmi query is cool but inflexible
  2. run .net script is cooler!

 

so that aside, the wmi query object i was using would return stacks of data which just wasn’t useful since i needed a relationship of data to be returned.  in this case, i wanted the package id and the program name from all advertisements on a sccm server.  i decided using a script was the best way to bring this data into opalis.  nothing new so far.  here’s the script i was piddling around with:

$myPackageID = @()
$myProgramName = @()

$myads = gwmi -Namespace root\sms\site_xyz -computername myComputer -Query "select packageid, programname from sms_program"

foreach ($ads in $myads) {
$myPackageID += $ads.packageid
$myProgramName += $ads.programname
}

 

basically, i’m creating two arrays: $mypackageid and $myprogramname.  now, in opalis, there’s a concept called “published data”.  to get information from script variables to published data, there’s a section of the run .net script object that allows you to specify what you want to collect.

image

 

if you’ll notice, i have two specified for two arrays: OPD_PackageID and myProgramName.  i did this specifically to show something interesting.  the results of the powershell script are going straight to the append line object.  the text reads:

{myPackageID from "Run .Net Script"}, {myProgramName from "Run .Net Script"}

 

this should put the value of packageid [comma] programname for every member of the array into a text file.  it doesn’t though.  instead it puts a [blank] [comma] programname.  hmmm.  why is this?  you’ve probably already clued in to the mystery.  it’s in the way you name things in published data.  take a look at this:

image image

 

of the two screenshots, #1 is the winner.  OPD_ is a best practice outlined in the opalis client guide for naming your items in the data bus.  unfortunately, positioning in the wrong section, like in #2, will fail every time.  just remember that variable name is referring to the variable in your script.

Comments