Saturday, March 23, 2013
Using WMI WbemScripting.SWbemLocator
More code, less talking.
$Locator = new-Object -comObject WbemScripting.SWbemLocator
$svc = $Locator.ConnectServer(".", "root\cimv2")
$ob = $svc.Get("Win32_Process")
$objs = $ob.Instances_(0)
for($x=0;$x -lt $objs.Count;$x++)
{
$mo = $objs.ItemIndex($x)
$propEnum = $mo.Properties_.GetType().InvokeMember("_NewEnum", [System.Reflection.BindingFlags]::InvokeMethod, $Null, $mo.Properties_, $Null)
$ret = $propEnum.MoveNext()
do
{
$prop = $propEnum.Current
[System.String]$s = $prop.Name
write-host $s.PadRight(30, " ") : $prop.Value
}
Until($propEnum.MoveNext() -eq $False)
write-host
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment