Custom Inventory can be used to detect what version of PowerShell is installed on computers. This article presents a sample custom inventory script and custom report that displays the custom inventory data. Please note that Symantec Support does not support custom scripting or reporting so modifications to the script and report must be made by the user.
1 Create a new custom data class that will store the registry information for each computer.
2 Create a Custom Inventory Script Task.
'Pick the appropriate WMI registry hive code and comment the line you don’t use Const HKEY_LOCAL_MACHINE = &H80000002 Set wshShell = WScript.CreateObject( "WScript.Shell" ) ComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) set nse = WScript.CreateObject ("Altiris.AeXNSEvent") nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}" 'Do not modify this GUID nse.Priority = 1 dim objDCInstance set objDCInstance = nse.AddDataClass ("PowerShell") 'Your Data Class Here set objDataClass = nse.AddDataBlock (objDCInstance) KeyPath = "SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine" 'Your Registry Key Path Here ValueName = "PowerShellVersion" 'Your Registy Entry Here Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 'Use the HKEY constant defined earlier and use the oReg function appropriate to the type of data in the registry entry error_returned = oReg.GetStringValue(HKEY_LOCAL_MACHINE,KeyPath,ValueName,Value) if error_returned <> 0 then KeyPath = "SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine" error_returned = oReg.GetStringValue(HKEY_LOCAL_MACHINE,KeyPath,ValueName,Value) end if set objDataRow = objDataClass.AddRow objDataRow.SetField 0, Value 'If your data class has more than one attribute add a line for each 'objDataRow.SetField 1, Value2 nse.Send 'Uncomment the line below for testing purposes 'MsgBox nse.Xml
3 Run the Custom Inventory Script task.
4 Create a Custom Report to view the data collected by the custom inventory.
select vc.[guid], vc.name, vc.[ip address], vc.[os name], ic.Version from Inv_PowerShell ic --Your custom data class table here join vComputer vc on vc.[guid] = ic._ResourceGuid