PowerShell for Windows Admins

Dec 5 2013   2:33PM GMT

CDXML–scripting creation

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

So far you’ve seen how to create CDXML files by hand – though you probably used cut and paste rather than typing everything from scratch.

Its time to bring a bit of automation to creating CDXML files. The XML is fairly simple and you’re only changing a couple of values so you can do this:

function new-cdxml {


param (



[string]$namespace = ‘ROOT\cimv2′,

[string]$path = “C:\Scripts\Modules\Hardware”


$code = @”

<?xml version=’1.0′ encoding=’utf-8′?>

<PowerShellMetadata xmlns=’http://schemas.microsoft.com/cmdlets-over-objects/2009/11′>

<Class ClassName=’$namespace\$class’>




<GetCmdletParameters DefaultCmdletParameterSet=’DefaultSet’>






$file = Join-Path -Path $path -ChildPath “$class.cdxml”

Write-Verbose -Message $file

Set-Content -Path $file -Value $code


I saved this as NewCDXML.ps1. This will eventually become the basis of a CDXML file creation module. I set defaults on the namespace and the path – feel free to change them if required.

The function is run as:

new-cdxml -class Win32_DiskDrive -noun PhysicalDisk

which produces this CDXML file

<?xml version=’1.0′ encoding=’utf-8′?>

<PowerShellMetadata xmlns=’http://schemas.microsoft.com/cmdlets-over-objects/2009/11′>

<Class ClassName=’ROOT\cimv2\Win32_DiskDrive’>




<GetCmdletParameters DefaultCmdletParameterSet=’DefaultSet’>





The Hardware.psd1 file needs to be altered:

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess

NestedModules = @(‘Win32_BIOS.cdxml’,





# Functions to export from this module

FunctionsToExport = @(‘Get-Bios’,




The module now looks like this:

£> Get-Command -Module Hardware

CommandType Name

———–             —-

Function            Get-Bios

Function             Get-ComputerSystem

Function            Get-PhysicalDisk

This makes creating additional components for your module much easier.

2  Comments on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • dmcdonough
    Is there a way to add filter parameters? I haven't seen much expansion on the InstanceCmdlets block.
    0 pointsBadges:
  • Richard Siddaway
    see http://itknowledgeexchange.techtarget.com/powershell/cdxml-filter-parameters/ for an example
    6,460 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: