Friday, October 3, 2008

Script to Force Hardware or Software Inventory

In my previous post I stated that we were allowing users to opt in to a collection on their own by putting a dummy exe on their computers.  The collection is setup to update its membership nightly.  However, clients need to run software inventory to report the new exe back to the Management Point.  Here's a VB script that clients can run to kick this process off.  Credit to Chris Stauffer at myitforum for the original code ( http://myitforum.com/cs2/blogs/cstauffer/archive/2007/04/04/script-to-perform-a-full-sms-inventory.aspx).  Also, I added in the Hardware Inventory version in case your adding registry keys, wmi classes, other HWinv type items.  If you want to verify that it's running check the inventoryagent.log file on the client.

On Error Resume Next

ForceSoftwareInventory()
ForceHardwareInventory()

'*********************************************************************************************************
'Force Software Inventory on the Client
'*********************************************************************************************************

Function ForceSoftwareInventory()
Set sho = CreateObject("WScript.Shell")
strSystemRoot = sho.expandenvironmentstrings("%SystemRoot%")
strCurrentDir = Left(Wscript.ScriptFullName, (InstrRev(Wscript.ScriptFullName, "\") -1))
'Run a SMS Software Inventory

Set cpApplet = CreateObject("CPAPPLET.CPAppletMgr")
Set actions = cpApplet.GetClientActions
For Each action In actions
    If Instr(action.Name,"Software Inventory Collection Cycle") > 0 Then
        action.PerformAction  
'        WScript.Echo action.name
End If
Next
End Function

'*********************************************************************************************************
'Force Hardware Inventory on the Client
'*********************************************************************************************************

Function ForceHardwareInventory()
Set sho = CreateObject("WScript.Shell")
strSystemRoot = sho.expandenvironmentstrings("%SystemRoot%")
strCurrentDir = Left(Wscript.ScriptFullName, (InstrRev(Wscript.ScriptFullName, "\") -1))
'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 Collection Cycle") > 0 Then
        action.PerformAction  
'        WScript.Echo action.name
End If
Next
End Function

2 comments:

Anonymous said...

Thanks for writing this.

Bill Phillips said...

no problem. glad to do it.