Tuesday, January 10, 2012

Creating System Footprints using PowerShell

 

 

WMI can retrieve a lot more object instances than you might think. If you submit a parent class, Get-WmiObject returns all instances of all derived classes. That's why a simple line like the following can get you all hardware-related instances:

PS> Get-WmiObject -Class CIM_PhysicalElement | Group-Object -Property __Class

 

Count Name                                                       Group

----- ----                                                       -----

    1 Win32_OnBoardDevice                     {\\DEMO5\root\cimv2:Win32_OnBoardDevice.Tag=...

    1 Win32_PhysicalMemoryArray  {\\DEMO5\root\cimv2:Win32_PhysicalMemoryArra...

    3 Win32_PortConnector                     {\\DEMO5\root\cimv2:Win32_PortConnector.Tag=...

    1 Win32_BaseBoard                                {\\DEMO5\root\cimv2:Win32_BaseBoard.Tag="Bas...

    1 Win32_SystemSlot                             {\\DEMO5\root\cimv2:Win32_SystemSlot.Tag="Sy...

    2 Win32_PhysicalMemory                  {\\DEMO5\root\cimv2:Win32_PhysicalMemory.Tag...

    1 Win32_SystemEnclosure               {\\DEMO5\root\cimv2:Win32_SystemEnclosure.Ta...

    4 Win32_PhysicalMedia                    {\\DEMO5\root\cimv2:Win32_PhysicalMedia.Tag=...

You can turn this into a lookup tool. Here's how:

PS> $col1 = @{Name='Key'; Expression={ ($_.__Class.ToString() -split '_')[-1] }}

PS> $info = Get-WmiObject -Class CIM_PhysicalElement | Select-Object *, $col1 | Group-Object -Property Key -AsHashTable -AsString

Use it like this:

PS> $info

 

Name                                                Value

----                                                -----

SystemEnclosure                 {@{Tag=System Enclosure 0; Status=; Name=Syst...

OnBoardDevice                      {@{Status=; Description=HD-Audio; __GENUS=2; ...

PhysicalMemory                    {@{__GENUS=2; __CLASS=Win32_PhysicalMemory; _...

PhysicalMedia                      {@{__GENUS=2; __CLASS=Win32_PhysicalMedia; __...

SystemSlot                              {@{Status=Unknown; SlotDesignation=PCI Expres...

BaseBoard                                 {@{Status=OK; Name=Base Board; PoweredOn=True...

PortConnector                      {@{Status=; Name=Port Connector; ExternalRefe...

PhysicalMemoryArray      {@{Status=; Name=Physical Memory Array; Repla...

PS> $info.baseboard

(...)

PS> $info.OnboardDevice

(...)

PS> $info.PhysicalMemory

(...)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.