PowerShell - Get serial numbers for computers in Active Directory
- Powershell Get System Serial Number
- Powershell Get Serial Number Remote Computer
- Powershell Get Serial Number Certificate
# Requires ActiveRoles CmdLets from Quest Software (They're free and awesome) - http://www.quest.com/powershell/activeroles-server.aspx |
Get-QADComputer -searchroot 'OU=yourcomputerOUname,dc=yourdomain,dc=com' -SizeLimit 0 | |
ForEach-Object { |
$hostname = $_.name |
$serialnumber = (Get-WMIObject Win32_BIOS -computer $hostname -ErrorAction SilentlyContinue).SerialNumber |
if (-not $serialnumber) { |
Add-Content d:logfilesofflinehosts.txt '$hostname is in offline' |
} |
else { |
Write-Host '$hostname,$serialnumber' # output to screen |
Add-Content d:logfilesserialnumberlist.txt '$hostname,$serialnumber' |
} |
} |
Getting Computer name, serial number and model of list of machines Welcome › Forums › General PowerShell Q&A › Getting Computer name, serial number and model of list of machines This topic contains 5 replies, has 3 voices, and was last updated. Getting the Computer name, serial number and model from all connected PC. Welcome › Forums › General PowerShell Q&A › Getting the Computer name, serial number and model from all connected PC. This topic contains 9 replies, has 7 voices, and was last updated.
commented Dec 15, 2017
ActiveRoles CmdLets NOT FREE - just sayin |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Over on MyItForum.com, I came upon a VBScript in a forum to find all the PNP entities associated with a USBController. I rewrote it in PowerShell and was pretty happy with the results so I thought I would share them. The first thing you need to understand is that the WMI class WIN32_USBControllerDevice describes the connection between USB controllers (The Antecedent) and their logical devices [CIM_LOGICALDEVICE] (the Dependent). Let me illustrate:
PS> gwmi Win32_USBControllerDevice |fl Antecedent,Dependent
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2658&SUBSYS_01891028&REV_033&2B8E0B4B&0&E8″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&2F35A3CB&0″
8086&DEV_2658&SUBSYS_01891028&REV_033&2B8E0B4B&0&E8″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&2F35A3CB&0″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2658&SUBSYS_01891028&REV_033&2B8E0B4B&0&E8″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBVID_04FC
&PID_00035&2604C4EE&0&1″
8086&DEV_2658&SUBSYS_01891028&REV_033&2B8E0B4B&0&E8″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBVID_04FC
&PID_00035&2604C4EE&0&1″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2658&SUBSYS_01891028&REV_033&2B8E0B4B&0&E8″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”HIDVID_04FC
&PID_00036&185E20EC&0&0000″
8086&DEV_2658&SUBSYS_01891028&REV_033&2B8E0B4B&0&E8″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”HIDVID_04FC
&PID_00036&185E20EC&0&0000″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&88AB5AD&0″
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&88AB5AD&0″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBVID_413C
&PID_81035&111B5EE1&0&1″
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBVID_413C
&PID_81035&111B5EE1&0&1″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”BTHMS_RFCOM
M6&3250FFA7&0&0″
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”BTHMS_RFCOM
M6&3250FFA7&0&0″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”BTHMS_BTHBR
B6&3250FFA7&0&1″
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”BTHMS_BTHBR
B6&3250FFA7&0&1″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”BTHMS_BTHPA
N6&3250FFA7&0&2″
8086&DEV_2659&SUBSYS_01891028&REV_033&2B8E0B4B&0&E9″
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”BTHMS_BTHPA
N6&3250FFA7&0&2″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_265A&SUBSYS_01891028&REV_033&2B8E0B4B&0&EA”
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&8904A15&0″
8086&DEV_265A&SUBSYS_01891028&REV_033&2B8E0B4B&0&EA”
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&8904A15&0″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_265B&SUBSYS_01891028&REV_033&2B8E0B4B&0&EB”
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&2F300F63&0″
8086&DEV_265B&SUBSYS_01891028&REV_033&2B8E0B4B&0&EB”
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
4&2F300F63&0″
Antecedent : JPSVISTA1rootcimv2:Win32_USBController.DeviceID=”PCIVEN_
8086&DEV_265C&SUBSYS_01891028&REV_033&2B8E0B4B&0&EF”
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
204&16530ED8&0″
8086&DEV_265C&SUBSYS_01891028&REV_033&2B8E0B4B&0&EF”
Dependent : JPSVISTA1rootcimv2:Win32_PnPEntity.DeviceID=”USBROOT_HUB
204&16530ED8&0″
Clear as mud right? These are WMI Path names and are not so readable. That’s ok for now; the point is that this class points to 2 other WMI entities.
![Powershell Get Serial Number Powershell Get Serial Number](/uploads/1/2/6/0/126030453/875481371.jpg)
Below is the VBScript that I got from here.
Powershell Get System Serial Number
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” & strComputer & “rootcimv2”)
Set colDevices = objWMIService.ExecQuery _
(“Select * From Win32_USBControllerDevice”)
Set colDevices = objWMIService.ExecQuery _
(“Select * From Win32_USBControllerDevice”)
For Each objDevice in colDevices
strDeviceName = objDevice.Dependent
strQuotes = Chr(34)
strDeviceName = Replace(strDeviceName, strQuotes, “”)
arrDeviceNames = Split(strDeviceName, “=”)
strDeviceName = arrDeviceNames(1)
Set colUSBDevices = objWMIService.ExecQuery _
(“Select * From Win32_PnPEntity Where DeviceID = ‘” & strDeviceName & “‘”)
For Each objUSBDevice in colUSBDevices
Wscript.Echo objUSBDevice.Description
WScript.Echo objUSBDevice.PnPDeviceID ‘ Changed from Description to PnPDeviceID
‘as this script can be altered to return any property
‘of the Win32_USBControllerDevice collection.
Next
Next
strDeviceName = objDevice.Dependent
strQuotes = Chr(34)
strDeviceName = Replace(strDeviceName, strQuotes, “”)
arrDeviceNames = Split(strDeviceName, “=”)
strDeviceName = arrDeviceNames(1)
Set colUSBDevices = objWMIService.ExecQuery _
(“Select * From Win32_PnPEntity Where DeviceID = ‘” & strDeviceName & “‘”)
For Each objUSBDevice in colUSBDevices
Wscript.Echo objUSBDevice.Description
WScript.Echo objUSBDevice.PnPDeviceID ‘ Changed from Description to PnPDeviceID
‘as this script can be altered to return any property
‘of the Win32_USBControllerDevice collection.
Next
Next
This script does a query to get all instances of WIN32_USBControllerDevice, then for each one it takes the DEPENDENT property and converts it to a query, it then executes that query (which gets the PNPEntities) and formats the description and deviceID.
We don’t have to do that in PowerShell. If you have a WMIPath, you can get the object it points to just by casting it with [WMI]. So that means that you can replace this script with the following one-liner (Note: I decided to sort and things to make it prettier [and to show off J] )
PS> gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} |
>> Sort Description,DeviceID | ft Description,DeviceID -auto
>>
>> Sort Description,DeviceID | ft Description,DeviceID -auto
>>
Description DeviceID
———– ——–
Bluetooth Device (Personal Area Network) BTHMS_BTHPAN6&3250FFA7&0&2
Bluetooth Device (RFCOMM Protocol TDI) BTHMS_RFCOMM6&3250FFA7&0&0
Dell Wireless 350 Bluetooth Module USBVID_413C&PID_81035&111B5EE…
Disk drive USBSTORDISK&VEN_COWON&PROD_IAU…
HID-compliant consumer control device HIDVID_045E&PID_00B9&COL016&2…
HID-compliant mouse HIDVID_045E&PID_00B9&COL026&2…
HID-compliant mouse HIDVID_04FC&PID_00036&185E20E…
Microsoft Bluetooth Enumerator BTHMS_BTHBRB6&3250FFA7&0&1
USB Human Interface Device USBVID_045E&PID_00B95&2616CD8…
USB Human Interface Device USBVID_04FC&PID_00035&2604C4E…
USB Mass Storage Device USBVID_0E21&PID_06000002F685D…
USB Root Hub USBROOT_HUB4&2F300F63&0
USB Root Hub USBROOT_HUB4&2F35A3CB&0
USB Root Hub USBROOT_HUB4&88AB5AD&0
USB Root Hub USBROOT_HUB4&8904A15&0
USB Root Hub USBROOT_HUB204&16530ED8&0
———– ——–
Bluetooth Device (Personal Area Network) BTHMS_BTHPAN6&3250FFA7&0&2
Bluetooth Device (RFCOMM Protocol TDI) BTHMS_RFCOMM6&3250FFA7&0&0
Dell Wireless 350 Bluetooth Module USBVID_413C&PID_81035&111B5EE…
Disk drive USBSTORDISK&VEN_COWON&PROD_IAU…
HID-compliant consumer control device HIDVID_045E&PID_00B9&COL016&2…
HID-compliant mouse HIDVID_045E&PID_00B9&COL026&2…
HID-compliant mouse HIDVID_04FC&PID_00036&185E20E…
Microsoft Bluetooth Enumerator BTHMS_BTHBRB6&3250FFA7&0&1
USB Human Interface Device USBVID_045E&PID_00B95&2616CD8…
USB Human Interface Device USBVID_04FC&PID_00035&2604C4E…
USB Mass Storage Device USBVID_0E21&PID_06000002F685D…
USB Root Hub USBROOT_HUB4&2F300F63&0
USB Root Hub USBROOT_HUB4&2F35A3CB&0
USB Root Hub USBROOT_HUB4&88AB5AD&0
USB Root Hub USBROOT_HUB4&8904A15&0
USB Root Hub USBROOT_HUB204&16530ED8&0
Not one to leave well enough alone, let’s guild this lilly:
PS> gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} |
>> Sort Manufacturer,Description,DeviceID |
>> Ft -GroupBy Manufacturer Description,Service,DeviceID
>>
>> Sort Manufacturer,Description,DeviceID |
>> Ft -GroupBy Manufacturer Description,Service,DeviceID
>>
Powershell Get Serial Number Remote Computer
Manufacturer: (Standard disk drives)
Description Service DeviceID
———– ——- ——–
Disk drive disk USBSTORDISK&VEN_COWO…
———– ——- ——–
Disk drive disk USBSTORDISK&VEN_COWO…
Manufacturer: (Standard system devices)
Description Service DeviceID
———– ——- ——–
USB Human Interface De… HidUsb USBVID_045E&PID_00B9…
USB Human Interface De… HidUsb USBVID_04FC&PID_0003…
———– ——- ——–
USB Human Interface De… HidUsb USBVID_045E&PID_00B9…
USB Human Interface De… HidUsb USBVID_04FC&PID_0003…
Manufacturer: (Standard USB Host Controller)
Description Service DeviceID
———– ——- ——–
USB Root Hub usbhub USBROOT_HUB4&2F300F…
USB Root Hub usbhub USBROOT_HUB4&2F35A3…
USB Root Hub usbhub USBROOT_HUB4&88AB5AD&0
USB Root Hub usbhub USBROOT_HUB4&8904A15&0
USB Root Hub usbhub USBROOT_HUB204&1653…
———– ——- ——–
USB Root Hub usbhub USBROOT_HUB4&2F300F…
USB Root Hub usbhub USBROOT_HUB4&2F35A3…
USB Root Hub usbhub USBROOT_HUB4&88AB5AD&0
USB Root Hub usbhub USBROOT_HUB4&8904A15&0
USB Root Hub usbhub USBROOT_HUB204&1653…
Powershell Get Serial Number Certificate
Manufacturer: Compatible USB storage device
Description Service DeviceID
———– ——- ——–
USB Mass Storage Device USBSTOR USBVID_0E21&PID_0600…
———– ——- ——–
USB Mass Storage Device USBSTOR USBVID_0E21&PID_0600…
Manufacturer: Dell
Description Service DeviceID
———– ——- ——–
Dell Wireless 350 Blue… BTHUSB USBVID_413C&PID_8103…
———– ——- ——–
Dell Wireless 350 Blue… BTHUSB USBVID_413C&PID_8103…
Manufacturer: Microsoft
Description Service DeviceID
———– ——- ——–
Bluetooth Device (Pers… BthPan BTHMS_BTHPAN6&3250F…
Bluetooth Device (RFCO… RFCOMM BTHMS_RFCOMM6&3250F…
HID-compliant consumer… HIDVID_045E&PID_00B9…
HID-compliant mouse mouhid HIDVID_045E&PID_00B9…
HID-compliant mouse mouhid HIDVID_04FC&PID_0003…
Microsoft Bluetooth En… BthEnum BTHMS_BTHBRB6&3250F…
———– ——- ——–
Bluetooth Device (Pers… BthPan BTHMS_BTHPAN6&3250F…
Bluetooth Device (RFCO… RFCOMM BTHMS_RFCOMM6&3250F…
HID-compliant consumer… HIDVID_045E&PID_00B9…
HID-compliant mouse mouhid HIDVID_045E&PID_00B9…
HID-compliant mouse mouhid HIDVID_04FC&PID_0003…
Microsoft Bluetooth En… BthEnum BTHMS_BTHBRB6&3250F…
In the past, people have thrown rocks at WMI for being difficult and obtuse. There is a ton of great information in WMI and now with PowerShell, you have a tool that makes it easy to find and manipulate. If you’ve looked at WMI in the past and given up, I encourage you to get some PowerShell skills under your belt and go at it again.
Enjoy!
![Powershell Powershell](/uploads/1/2/6/0/126030453/432716634.jpg)
Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx