Video Screencast Help

Custom Inventory 7.1 and Powershell

Created: 09 May 2012 • Updated: 02 Jul 2012 | 7 comments
montepe's picture
This issue has been solved. See solution.

I am a complete noob at scripting, and took my first steps into Windows Powershell a few weeks ago.

I created a script to read certain distribution groups in AD and create a list of the result. But I want to put this in the SQL database using Custom Inventory 7.1.

Is there anyone who has a sample powershell script to use for Custom Inventory?

You can see the syntax of my script below. Any tips of the syntax I need to add for Custom Inventory are also welcome.

 

my script:
 

get-adgroup -filter * -SearchBase 'OU=app-v,OU=groepen,OU=PA2012,DC=pa,DC=be' -searchscope onelevel |select -expand name|foreach {$_ -replace "@DG-APPV-",""}

Comments 7 CommentsJump to latest comment

rpoag's picture

I am working on this as well. I tested this in a previous version and found it would not work. I am trying again with SMP 7.1 and powerhell 2.0. I am having issues figuring out how to add rows to the dataclass. Once I get that I can give you a sample.

Ryan Poag
Northrop Grumman
If your question has been resolved, please be sure to "Mark as Solution"! Thank you.

montepe's picture

Thanks rpoag,

I'm awaiting your reply. :-)

rpoag's picture

Here you go. Here is another sample I found, https://www-secure.symantec.com/connect/downloads/gather-bitlocker-encryption-status-powershell-custom-inventory, on connect which I used to get the setfield command to work. Let me know if you have any questions.

 

#************************DO NOT EDIT********************************
$nse = new-object -comobject Altiris.AeXNSEvent
$nse.priority = 1
$nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
#************************DO NOT EDIT********************************

#Modify this varaible with the custom data class guid
$objDCInstance = $nse.AddDataClass("{476b9e22-b629-498f-aaaa-ea253de46e29}")

$objDataClass = $nse.AddDataBlock($objDCInstance)
$pathlist = get-childitem -path c:\ | where {$_.psiscontainer} | where {$_.name -notmatch "windows"} | convert-path | get-childitem -filter web.config -recurse | convert-path

foreach ($path in $pathlist ) {
#Add new row of data
$objDataRow = $objDataClass.AddRow()
$objDataRow.SetField(0, $path)
}

#Send the data
$nse.sendqueued()

Ryan Poag
Northrop Grumman
If your question has been resolved, please be sure to "Mark as Solution"! Thank you.

SOLUTION
montepe's picture

helllo rpoag,

I would like to know where to place my own query now?

can I do it like this?

#************************DO NOT EDIT********************************
$nse = new-object -comobject Altiris.AeXNSEvent
$nse.priority = 1
$nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
#************************DO NOT EDIT********************************

#Modify this varaible with the custom data class guid
$objDCInstance = $nse.AddDataClass("{476b9e22-b629-498f-aaaa-ea253de46e29}")

$objDataClass = $nse.AddDataBlock($objDCInstance)
$pathlist = get-childitem -path c:\ | where {$_.psiscontainer} | where {$_.name -notmatch "windows"} | convert-path | get-childitem -filter web.config -recurse | convert-path

foreach ($path in $pathlist ) {
#Add new row of data
$objDataRow = $objDataClass.AddRow()
$objDataRow.SetField(0, $path)
}

get-adgroup -filter * -SearchBase 'OU=app-v,OU=groepen,OU=PA2012,DC=ab,DC=be' -searchscope onelevel |select -expand name|foreach {$_ -replace "@DG-APPV-",""}

#Send the data
$nse.sendqueued()

 

montepe's picture

When I check the queues dir on my client, this is what in the nse file:
The data, retrieved from my powershell command is not there. (I think)
Anybody an idea what I do wrong?

 

<?xml version="1.0"?>
<message>
<to>{1592B913-72F3-4C36-91D2-D4EDA21D2F96}</to>
<priority>1</priority>
<msgId>{AC5C0AF9-9D03-4F0E-AF73-B0FDAB11385A}</msgId>
<time>20120629150427.186000-120</time>
<from>
 <resource typeGuid="{493435F7-3B17-4C4C-B07F-C23E7AB7781F}" guid="{926BB585-9A3B-4997-89F8-76B75D8AEAD7}" name="CCA152893">
  <key name="name.domain" value="CCA152893.DOMAIN00"/>
  <key name="fqdn" value="CCA152893.pa.be"/>
  <key name="uniqueid" value="W02Z/P+AB2vL5RnBnWoAog=="/>
  <key name="uniqueid" value="8GPkG8JhvPmYCK8puCa70A=="/>
  <key name="uniqueid" value="9KZDiNUBnoxYTFQObcvXAg=="/>
  <key name="uniqueid" value="9WNyU9ZV6utKvq8AYhM8cA=="/>
 </resource>
</from>
<body>
 <inventory>
  <dataClass name="{ 3f5f3ca1-1189-458d-9fbc-2cdca3a60202}">
   <data>
    <resource partialUpdate="false">
     <row c0="[NULL()]" hash="eiDF23OXLMnSQS3CaE573g=="/>
    </resource>
   </data>
  </dataClass>
 </inventory>
</body>
</message>

jason.f's picture

Does the GUID match the custom data class you created? Also, you need to set your powershell AD query to store it's data  in a variable then pass that to the Add Data row. I'm not sure what your AD query is going to return so you might need to check the properties so you get the correct data. You can see that I added " $ADQuery = " before your query, thats where the objects will be stored. Run that command just like that from your powershell prompt and then pipe $ADQuery | Get-Member and that will tell you what properties are available. You might need to use something like $ADQuery.LastName if thats what your looking for. You also might need to use a foreach if more than one object is returned.

I've modified your script below.

 

#************************DO NOT EDIT********************************
$nse = new-object -comobject Altiris.AeXNSEvent
$nse.priority = 1
$nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
#************************DO NOT EDIT********************************

#Modify this varaible with the custom data class guid
$objDCInstance = $nse.AddDataClass("{476b9e22-b629-498f-aaaa-ea253de46e29}")

$objDataClass = $nse.AddDataBlock($objDCInstance)

$ADQuery = get-adgroup -filter * -SearchBase 'OU=app-v,OU=groepen,OU=PA2012,DC=ab,DC=be' -searchscope onelevel |select -expand name|foreach {$_ -replace "@DG-APPV-",""}

#Add new row of data
$objDataRow = $objDataClass.AddRow()
$objDataRow.SetField(0, $ADQuery.LastName) #Modify this for what property you want to store in the DB

#Send the data
$nse.sendqueued()

montepe's picture

Thanks rpoag and jason.f for your valuable input.
I got it working now.

smiley