Enumerate WMI v1.1 (Powershell)

<#
.SYNOPSIS
    Gets all classes and properties in the specified WMI namespace.
.DESCRIPTION
    Gets all classes and properties in the specified WMI namespace and below.
.PARAMETER ComputerName
    Specify host to scan.
.PARAMETER Namespace
    Specify the WMI namespace to scan.
.PARAMETER
    Recursively dump all WMI namespaces.
.EXAMPLE
    C:\>powershell -file EnumWMI.ps1 -Namespace "root\ccm" [-Recurse]
    Return a list of all classes and properties in the "root\ccm" WMI namespace and in all sub-namespaces
.LINK
    http://www.1st-technologies.com/library/scripts/enumerate-wmi
.NOTES
    Name     : Enumerate WMI
    Version  : 1.1
    Copyright: 1st Technologies, Inc. 2015
    Author   : 1st Technologies, Inc.
    Date     : June 25, 2015
#>


[CmdletBinding()]
Param(
    [Parameter(Mandatory = $false, Position=0, HelpMessage="Specify host to scan.")]
    [ValidateNotNullOrEmpty()]
    [string]$ComputerName = ".",

    [Parameter(Mandatory = $false, Position=1, HelpMessage="Specify the WMI namespace to scan.")]
    [ValidateNotNullOrEmpty()]
    [string]$Namespace = "root\cimv2",

    [Parameter(Mandatory = $false, Position=2, HelpMessage="Recursively dump all WMI namespaces.")]
    [switch]$Recurse = $false
)


# Enumerate all WMI namespaces in the specified WMI root
Function Get-WMINamespaces{
    param([string]$WMINamespace)
    Get-WMIObject -ComputerName $ComputerName -Namespace $WMINamespace -Class __Namespace | ForEach-Object{
        ($SubNameSpace = "{0}\{1}" -f $_.__NAMESPACE, $_.Name)
        Get-WMINamespaces $SubNameSpace
    }
}


## MAIN ##
write-verbose "Replacing forward slashes in '$Namespace' with backslashes..."
$Namespace = $Namespace.Replace('/','\')

ForEach ($Class in (Get-WmiObject -ComputerName $ComputerName -Namespace $Namespace -List)){
    write-verbose("Enumerating properties of '{0}'..." -f $Class.Name)
    ForEach ($Property in $Class.Properties){
        write-output ("{0},{1},{2},{3}" -f $ComputerName, $Namespace, $Class.Name, $Property.Name)
    }
}


If ($Recurse -eq $true){
    write-verbose("Enumerating Sub-Namespaces in '{0}'..." -f $Namespace)
    ForEach ($SubNamespace in (Get-WMINamespaces -WMINamespace $Namespace)){
        write-verbose("Enumerating Sub-Namespaces in '{0}'..." -f $SubNamespace)
        ForEach ($Class in (Get-WmiObject -ComputerName $ComputerName -Namespace $SubNamespace -List)){
            write-verbose("Enumerating properties of '{0}'..." -f $Class.Name)
            ForEach ($Property in $Class.Properties){
                write-output ("{0},{1},{2},{3}" -f $ComputerName, $SubNamespace, $Class.Name, $Property.Name)
            }
        }
    }
}

Document Actions