Continuing the creation of a Hardware investigation module – its a simple matter to add a cmdlet to retrieve the computer system data ie Win32_ComputerSystem
First create a CDXML file like this:
<?xml version="1.0" encoding="utf-8"?>
<PowerShellMetadata xmlns="http://schemas.microsoft.com/cmdlets-over-objects/2009/11">
<Class ClassName="ROOT\cimv2\Win32_ComputerSystem">
<Version>1.0</Version>
<DefaultNoun>ComputerSystem</DefaultNoun>
<InstanceCmdlets>
<GetCmdletParameters DefaultCmdletParameterSet="DefaultSet">
</GetCmdletParameters>
</InstanceCmdlets>
</Class>
</PowerShellMetadata>
The only difference from the Win32_BIOS.cdxml is the WMI class and the default noun
Save in your Hardware module folder as Win32_ComputerSystem.cdxml
Modify the hardware.psd1 file in two places –
NestedModules = @(‘Win32_BIOS.cdxml’,
‘Win32_ComputerSystem.cdxml’ )
AND
FunctionsToExport = @(‘Get-Bios’,
‘Get-ComputerSystem’)
Save the hardware.psd1 file.
Now when you open up PowerShell
£> Get-Command -Module Hardware
CommandType Name ModuleName
———– —- ———-
Function Get-Bios Hardware
Function Get-ComputerSystem Hardware
£> Get-ComputerSystem | Format-List
Domain : Manticore.org
Manufacturer : Microsoft Corporation
Model : Virtual Machine
Name : WIN81
PrimaryOwnerName : Richard
TotalPhysicalMemory : 1857605632
Note default display is a table.
For now we’ll keep adding investigative cmdlets to our module – though there are some methods on Win32_ComputerSystem we’ll be adding to our module later.