Wednesday, April 16, 2008

SCCM - Script to Run FULL Software and Hardware Inventory

These have proven useful for any number of situations. There are numerous resources out there to kick off software & hardware delta scans, however scripts to kick off full scans are rare. Like...say for example Symantec Ghost drops and executable that is dated 1601 that causes half of your enterprise to not report software inventory (more on that to come), the easiest resolution is to drop skpswi.dat into the folder and re-run a full scan.

What MS has to say about Software inventory:
http://technet.microsoft.com/en-us/library/bb632607.aspx

What MS has to say about Hardware inventory:
http://technet.microsoft.com/en-us/library/bb632916.aspx

(Appologies for the small size, it was the easiest way to keep the formating in both the blog & copying into notepad.)

Script: Full software inventory scan

'Reset SMS Software Inventory Action to force a full HW Inventory Action 

sInventoryActionID = "{00000000-0000-0000-0000-000000000002}"

' Get a connection to the "root\ccm\invagt" namespace (where the Inventory agent lives)
Dim oLocator
Set oLocator = CreateObject("WbemScripting.SWbemLocator")

Dim oServices
Set oServices = oLocator.ConnectServer( , "root\ccm\invagt")

' Delete the specified InventoryActionStatus instance
oServices.Delete "InventoryActionStatus.InventoryActionID=""" & sInventoryActionID & """"

'Pause 3 seconds to allow the action to complete.
wscript.sleep 3000
'######################################
'Run a SMS Software Inventory
Set cpApplet = CreateObject("CPAPPLET.CPAppletMgr")
Set actions = cpApplet.GetClientActions
For Each action In actions
If Instr(action.Name,"Hardware Inventory") > 0
Then action.PerformAction
End if
Next




Script: Full hardware inventory scan

'Reset SMS Hardware Inventory Action to force a full HW Inventory Action
sInventoryActionID = "{00000000-0000-0000-0000-000000000001}"

' Get a connection to the "root\ccm\invagt" namespace (where the Inventory agent lives)
Dim oLocator
Set oLocator = CreateObject("WbemScripting.SWbemLocator")

Dim oServices
Set oServices = oLocator.ConnectServer( , "root\ccm\invagt")

' Delete the specified InventoryActionStatus instance
oServices.Delete "InventoryActionStatus.InventoryActionID=""" & sInventoryActionID & """"

'Pause 3 seconds to allow the action to complete. wscript.sleep 3000

'######################################

'Run a SMS Hardware Inventory
Set cpApplet = CreateObject("CPAPPLET.CPAppletMgr")
Set actions = cpApplet.GetClientActions
For Each action In actions
If Instr(action.Name,"Hardware Inventory") > 0 Then
action.PerformAction
End if
Next


8 comments:

Anonymous said...

Thanks for the edited script, but this time the formatting in the last paragraph is messed up :)

Will Kaiser said...

Fixed. This template can be painful at times.

Russ Rimmerman said...

I'm getting a
(12, 1) SWbemServicesEx: Not found

Any ideas?

Anonymous said...

Thanks for posting it was a big help. One comment, your Software Inventory script is running the Hardware Inventory Action from the CPApplet object. I believe it should be "Software Inventory Collection Cycle"

Joseph Zacharie said...

It must be :

"If Instr(action.Name,"Software Inventory") > 0 Then "

Nick said...

This worked great for me, thank-you!

Digitalbit said...
This comment has been removed by the author.
eddyshaw9272711 said...

I found your blog site on google and examine just a few of your early posts. Proceed to keep up the excellent operate. I just further up your RSS feed to my MSN Information Reader. In search of forward to studying more from you afterward!… casino slots