#PSTip List all WMI namespaces on a system

Note: This tip requires PowerShell 2.0 or above.

In WMI, a namespace is a collection of classes. There are many WMI namespaces on a system and each namespace might contain more namespaces. Each WMI namespace is an instance of __NAMESPACE system class. So, we can use Get-WmiObject cmdlet to list all WMI namespaces on a system.

Get-WmiObject -Class __NAMESPACE | select Name

But since Get-WmiObject defaults to root\cimv2 namespace, we get namespaces under root\cimv2 namespace only.

Here is a simple function that helps you get all WMI namespaces on a system in a recursive manner.

Function Get-WmiNamespace {
    Param (
        $Namespace='root'
    )
    Get-WmiObject -Namespace $Namespace -Class __NAMESPACE | ForEach-Object {
            ($ns = '{0}\{1}' -f $_.__NAMESPACE,$_.Name)
            Get-WmiNamespace $ns
    }
}
Share on: