Enumerate WMI 2.0 (Powershell)
<#
.SYNOPSIS
Gets all namespaces, classes, methods and properties in the specified WMI namespace.
.DESCRIPTION
Gets all namespaces, classes, methods and properties in the specified WMI namespace and below.
.PARAMETER ComputerName
Specify host to scan.
.PARAMETER Namespace
Specify the WMI namespace to scan.
.PARAMETER Recurse
Recursively dump all WMI namespaces.
.EXAMPLE
-------------------------- EXAMPLE 1 --------------------------
PS C:\>Enumerate-WMI
Return a list of all namespaces, classes, methods and properties in the "root\cimv2" WMI namespace on the local system
-------------------------- EXAMPLE 2 --------------------------
PS C:\>Enumerate-WMI -Namespace "root\ccm" -Recurse
Return a list of all namespaces, classes, methods and properties in the "root\ccm" WMI namespace and all sub-namespaces on the local system
-------------------------- EXAMPLE 3 --------------------------
PS C:\>Enumerate-WMI -ComputerName SERVER1 -Namespace "root\sms" -Recurse
Return a list of all namespaces, classes and properties in the "root\sms" WMI namespace and all sub-namespaces on SERVER1
.LINK
http://www.1st-technologies.com/library/scripts/enumerate-wmi-2-0-powershell
.NOTES
Name : Enumerate WMI
Version : 2.0
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 '{0}'..." -f $Class.Name)
ForEach ($Property in $Class.Properties){
write-output ("{0},{1},{2},{3},{4}" -f $ComputerName, $Namespace, $Class.Name, "Property", $Property.Name)
}
ForEach ($Method in $Class.Methods){
write-output ("{0},{1},{2},{3},{4}" -f $ComputerName, $Namespace, $Class.Name, "Method", $Method.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 '{0}'..." -f $Class.Name)
ForEach ($Property in $Class.Properties){
write-output ("{0},{1},{2},{3},{4}" -f $ComputerName, $SubNamespace, $Class.Name, "Property", $Property.Name)
}
ForEach ($Method in $Class.Methods){
write-output ("{0},{1},{2},{3},{4}" -f $ComputerName, $Namespace, $Class.Name, "Method", $Method.Name)
}
}
}
}Document Actions
