The idea has been popping up in my mind every now and then: a PowerShell class that would hold "all" available hardware information on a computer.
This is the first version, still highly experimental, betaish.
It will work for the local computer only; future versions will allow gathering info on remote computers as well.
This class has been tested on my own computers only, in PowerShell 5.1 and 7.2.
The information is gathered through WMI, no surprise there.
Gathering the information roughly takes 2 seconds on my fastest computer (or double that time in PowerShell ISE).
I tried a multi-threaded approach too, expecting a gain in performance, but that version took about 8 seconds to gather the requested information, so for now I will concentrate on the single-threaded version.
In a PowerShell session, run the script containing the class' source code once.
Next, to gather information, run the following command:
$mycomputer = [Computer]:New( )
Get a quick overview of the gathered information:
$mycomputer
Or view more details, e.g. for the first network adapter:
$mycomputer.NIC[0] | Format-List
The help text is always available, just type:
[Computer]::Help
class Computer { static [string]$Version = '1.00' static [string]$Copyrights = 'Rob van der Woude' static [string]$ProductPage = 'https://www.robvanderwoude.com/powershellcomputerclass.php' static [string]$Help = @" Computer class, Version {0} Make basic hardware infomation available in a class Copyrights {1} {2} {3} How to use: =========== Create an instance of the Computer class using the following command: `$computer = [Computer]::New( ) After gathering hardware information for a couple of seconds, `$computer will have the information available through its properties and methods: --------- --------- ------------------------------- ---------- Property: DataType: Information on this computer's: WMI class: --------- --------- ------------------------------- ---------- Name System.String computer name IPAddress System.String local IP address BIOS System.Object BIOS root/CIMV2/Win32_BIOS CDROM System.Object CD-ROM drive(s) root/CIMV2/Win32_CDROMDrive CPU System.Object processor(s) root/CIMV2/Win32_Processor HDD System.Object harddisk(s) root/Microsoft/Windows/Storage/MSFT_PhysicalDisk Keyboard System.Object keyboard(s) root/CIMV2/Win32_Keyboard MainBoard System.Object main board root/CIMV2/Win32_BaseBoard Memory System.Object memory root/CIMV2/Win32_PhysicalMemory Monitor System.Object monitor(s) root/WMI/WmiMonitorID Mouse System.Object mouse (or mice) root/CIMV2/Win32_PointingDevice NIC System.Object physical network adapter(s) root/CIMV2/Win32_NetworkAdapter Printers System.Object physical local printer(s) root/CIMV2/Win32_Printer Slots System.Object system slots root/CIMV2/Win32_SystemSlot Sound System.Object sound card(s) root/CIMV2/Win32_SoundDevice USB System.Object USB controller(s) root/CIMV2/Win32_USBController Video System.Object video card(s) root/CIMV2/Win32_VideoController Windows System.Object Windows version root/CIMV2/Win32_OperatingSystem WinSat System.Object WinSat system scores root/CIMV2/Win32_WinSAT --------- --------- ---------- ---------- Property: DataType: Number of: WMI class: --------- --------- ---------- ---------- _AGP System.Int32 AGP slots root/CIMV2/Win32_SystemSlot _AGP2X System.Int32 AGP2X slots root/CIMV2/Win32_SystemSlot _AGP4X System.Int32 AGP4X slots root/CIMV2/Win32_SystemSlot _AGP8X System.Int32 AGP8X slots root/CIMV2/Win32_SystemSlot _Cardbus System.Int32 Cardbus slots root/CIMV2/Win32_SystemSlot _CDROMs System.Int32 CD-ROM drives root/CIMV2/Win32_CDROMDrive _COMPorts System.Int32 serial ports root/CIMV2/Win32_SerialPort _EISA System.Int32 EISA slots root/CIMV2/Win32_SystemSlot _HDDs System.Int32 harddisk drives root/Microsoft/Windows/Storage/MSFT_PhysicalDisk _ISA System.Int32 ISA slots root/CIMV2/Win32_SystemSlot _LPTPorts System.Int32 parallel ports root/CIMV2/Win32_ParallelPort _MemoryGB System.Int32 GigaBytes of memory root/CIMV2/Win32_PhysicalMemory _MemoryModules System.Int32 memory modules root/CIMV2/Win32_PhysicalMemory _MemorySockets System.Int32 memory sockets root/CIMV2/Win32_PhysicalMemoryArray _Monitors System.Int32 monitors root/WMI/WmiMonitorID _PCI System.Int32 PCI slots root/CIMV2/Win32_SystemSlot _PCIE System.Int32 PCI-E slots root/CIMV2/Win32_SystemSlot _PCIX System.Int32 PCI-X slots root/CIMV2/Win32_SystemSlot _PCMCIA System.Int32 PCMCIA slots root/CIMV2/Win32_SystemSlot _USB2 System.Int32 USB controllers (except USB 3) root/CIMV2/Win32_USBController _USB3 System.Int32 USB 3 controllers root/CIMV2/Win32_USBController _VESA System.Int32 VESA slots root/CIMV2/Win32_SystemSlot Static Members: =============== ----------------------- ------------ ------ Properties and Methods: Description: Value: ----------------------- ------------ ------ [Computer]::Version This class' version {0} [Computer]::Copyrights Author's name {2} [Computer]::ProductPage This class' webpage {3} [Computer]::Help This help text [Computer]::OpenProductPage( ) Open this class' webpage [Computer]::New( ) Create new instance of this class "@ -f [Computer]::Version, [char]0x00A9, [Computer]::Copyrights, [Computer]::ProductPage static [void]OpenProductPage( ) { Start-Process -FilePath $( [Computer]::ProductPage ) } [string]$Name = $Env:ComputerName [string]$IPAddress = $( [System.Net.Dns]::Resolve( $Env:ComputerName ).AddressList.IPAddressToString ) [object]$BIOS [object]$CDROM [object]$CPU [object]$HDD [object]$Keyboard [object]$MainBoard [object]$Memory [object]$Monitor [object]$Mouse [object]$NIC [object]$Printers [object]$Slots [object]$Sound [object]$USB [object]$Video [object]$Windows [object]$WinSat [int]$_AGP [int]$_AGP2X [int]$_AGP4X [int]$_AGP8X [int]$_Cardbus [int]$_CDROMs [int]$_COMPorts [int]$_EISA [int]$_HDDs [int]$_ISA [int]$_LPTPorts [int]$_MemoryGB [int]$_MemoryModules [int]$_MemorySockets [int]$_Monitors [int]$_PCI [int]$_PCIE [int]$_PCIX [int]$_PCMCIA [int]$_USB2 [int]$_USB3 [int]$_VESA Computer( ) { $this.BIOS = $( Get-CimInstance -ClassName Win32_BIOS ) $this.CDROM = $( Get-CimInstance -ClassName Win32_CDROMDrive | Where-Object { $_.Name -notmatch 'virtual' } ) $this.CPU = $( Get-CimInstance -ClassName Win32_Processor ) $this.HDD = $( Get-CimInstance -ClassName MSFT_PhysicalDisk -Namespace root/Microsoft/Windows/Storage ) $this.Keyboard = $( Get-CimInstance -ClassName Win32_Keyboard ) $this.MainBoard = $( Get-CimInstance -ClassName Win32_BaseBoard ) $this.Memory = $( Get-CimInstance -ClassName Win32_PhysicalMemory ) $this.Monitor = $( Get-CimInstance -ClassName WmiMonitorID -Namespace root/WMI ) $this.Mouse = $( Get-CimInstance -Classname Win32_PointingDevice ) $this.NIC = $( Get-CimInstance -ClassName Win32_NetworkAdapter | Where-Object { $_.Speed -gt 0 } ) # physical adapters only $this.Printers = $( Get-CimInstance -ClassName Win32_Printer | Where-Object { $_.PrintProcessor -ne 'winprint' -and $_.Local } ) # physical local printers only $this.Slots = $( Get-CimInstance -ClassName Win32_SystemSlot ) $this.Sound = $( Get-CimInstance -ClassName Win32_SoundDevice | Where-Object { $_.Manufacturer -ne 'Microsoft' } ) # physical soundcards only $this.USB = $( Get-CimInstance -ClassName Win32_USBController ) $this.Video = $( Get-CimInstance -ClassName Win32_VideoController ) $this.Windows = $( Get-CimInstance -ClassName Win32_OperatingSystem ) $this.WinSat = $( Get-CimInstance -ClassName Win32_WinSAT -Filter "TimeTaken='MostRecentAssessment'" ) $this._AGP = $( $this.Slots | Where-Object { $_.ConnectorType -eq 73 } | Measure-Object ).Count $this._AGP2X = $( $this.Slots | Where-Object { $_.ConnectorType -eq 81 } | Measure-Object ).Count $this._AGP4X = $( $this.Slots | Where-Object { $_.ConnectorType -eq 82 } | Measure-Object ).Count $this._AGP8X = $( $this.Slots | Where-Object { $_.ConnectorType -eq 99 } | Measure-Object ).Count $this._Cardbus = $( $this.Slots | Where-Object { $_.ConnectorType -eq 52 } | Measure-Object ).Count $this._CDROMs = $( $this.CDROM | Measure-Object ).Count $this._COMPorts = $( Get-CimInstance -ClassName Win32_SerialPort | Measure-Object ).Count $this._EISA = $( $this.Slots | Where-Object { $_.ConnectorType -eq 45 } | Measure-Object ).Count $this._HDDs = $( $this.HDD | Measure-Object ).Count $this._ISA = $( $this.Slots | Where-Object { $_.ConnectorType -eq 44 } | Measure-Object ).Count $this._LPTPorts = $( Get-CimInstance -ClassName Win32_ParallelPort | Measure-Object ).Count $_Memory = 0 $this.Memory.Capacity | ForEach-Object { $_Memory += $_ } $this._MemoryGB = $( $_Memory / 1GB ) $this._MemoryModules = $( $this.Memory | Measure-Object ).Count $this._MemorySockets = $( Get-CimInstance -ClassName Win32_PhysicalMemoryArray ).MemoryDevices $this._Monitors = $( $this.Monitor | Measure-Object ).Count $this._PCMCIA = $( $this.Slots | Where-Object { $_.ConnectorType -gt 46 -and $_.ConnectorType -lt 51 } | Measure-Object ).Count $this._PCI = $( $this.Slots | Where-Object { $_.ConnectorType -eq 43 -or $_.ConnectorType -eq 80 } | Measure-Object ).Count $this._PCIE = $( $this.Slots | Where-Object { $_.ConnectorType -eq 100 } | Measure-Object ).Count $this._PCIX = $( $this.Slots | Where-Object { $_.ConnectorType -eq 88 } | Measure-Object ).Count $this._USB3 = $( $this.USB | Where-Object { $_.Name -match 'USB ?3' } | Measure-Object ).Count # not very reliable, as this relies on the description $this._USB2 = $( $this.USB | Measure-Object ).Count - $this._USB3 # total number of USB controllers - number of USB 3 controllers $this._VESA = $( $this.Slots | Where-Object { $_.ConnectorType -eq 46 } | Measure-Object ).Count } }
page last modified: 2021-12-20; loaded in 0.0163 seconds