Tuesday, April 29, 2014

Powershell: How to recursively enumerate through namespaces

$ns
function enumNamespaces
{
    write-host $ns
    $Names = Get-WmiObject -namespace $ns -class __NameSpace | select name  
    foreach($n in $Names)
    {
         $ns = $ns + "\" + $n.Name
         enumNamespaces
         $ns = $ns.Replace("\" + $n.Name, "")     
    }        
}  

$ns = "root"
enumNamespaces

No comments:

Post a Comment