Categories

Discovering namespaces

Next point on the journey of discovery through CIM is finding the namespaces installed on a machine.  I showed how to do this using Get-WmiObject in PowerShell and WMI but this time round decided to come up to date and use Get-CimInstance

function get-cimnamespace {
param (
[string]$namespace = 'root/cimv2'
)

Get-CimInstance -ClassName __NameSpace -Namespace $namespace |
select @{N='Name'; E={"$($_.CimSystemProperties.NameSpace)/$($_.Name)"}}

}

This simply searches for instances of the __NameSpace class in a given starting name space. Default is root/cimv2.  By using select-object to create a calculated field I can append the name of the namespace to the current namespace to get the full path.

Next time I’ll show how to use recursion to dig through the namespaces we’re discovering to find any namespaces they contain.

Leave a Reply