Share via


Use PowerShell to get OS inventory from SCCM

One can query ConfgiMgr Server for the OS or any hardware related information as ConfigMgr collects hardware inventory from the endpoints it manages.

Below is a small script code showing how it could be done:

DexterPC – Machine for which we need OS Info

DexSCCM – SCCM Server with SMS provider installed

Root/SMS/Site_DEX  - where DEX is 3 letter site code

001
002
003

 $Computer= 'DexterPC'
 $Query = "Select Version,CSDVersion,SystemDirectory,Installdate,LastBootuptime,installdate,caption,Description from SMS_G_System_OPERATING_SYSTEM JOIN SMS_R_System ON SMS_R_System.ResourceID = SMS_G_System_OPERATING_SYSTEM.ResourceID where SMS_R_System.NetbiosName='$computer'"
 Get-WmiObject -Query $Query -ComputerName DexSCCM -Namespace root/SMS/Site_DEX

Have created a PowerShell Function which first tries to query the Remote machine over WMI for the OS info and if the machine is offline then we can pass on the SCCM Server name and it will query SCCM for the same info. It is available for download  here ​and my blog post shedding little light on the topic and the function can be found  here