Inventorying hardware with PowerShell
Often times, a system administrator needs to identify what hardware is installed in their environment. This could be for an asset tracking project, finding available resources, or even identifying older equipment that needs to be retired. Most hardware information on a system is stored in WMI and can be accessed via in-built PowerShell functions or via WMI queries.
In this recipe, we will review the various methods for gathering inventory information from our local system. In addition to collecting from the local system, these methods can be expanded to include remote systems.
How to do it...
We can review the various methods for gathering inventory information as follows:
Gather disk information from the local system.
$TargetSystem="." $myCim = New-CimSession -ComputerName $TargetSystem Get-Disk -CimSession $myCim
When executed, the results will be displayed similar to the following screenshot:
Review the contents of the
Get-Disk
function.Get-Content Function...