header image

CDXML: Add a cmdlet for computer system

Posted by: | December 2, 2013 | No Comment |

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">

      <GetCmdletParameters DefaultCmdletParameterSet="DefaultSet">


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’ )



FunctionsToExport = @(‘Get-Bios’,

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.

under: CDXML, PowerShell and CIM, PowerShell and WMI, PowerShell V3, PowerShell v4