Sign in to follow this  
Followers 0
NunoBorges

Dump a WMI class

5 posts in this topic

Viva,

Is it possible to put this code to work, or am I so crazy?

On line 23, in "$ objItem." I plan on using a variable, or is there a better way to get the same result?

Best regards

I thank for your time.

$colItems = ""
$strComputer = @ComputerName
$strNamespace = "\root\CIMV2"
$strClass = "Win32_ComputerSystem"
$Output = ""
$Output &= "WMI for " & $strComputer & @CRLF
$Output &= "" & @CRLF
$objWMIServiceClass = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & $strNamespace)
$objClass = $objWMIServiceClass.Get($strClass)
ConsoleWrite("$objClass.count: " & $objClass.Properties_().count & @CRLF)
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & $strNamespace)
$colItems = $objWMIService.ExecQuery("SELECT * FROM " & $strClass, "WQL");, 0x10 + 0x20)
ConsoleWrite("$colItems.count: " & $colItems.count & @CRLF)
For $objItem In $colItems
If IsObj($colItems) Then
  For $objProperty In $objClass.Properties_()
   $Output &= $objProperty.Name & ": " & $objItem.$objProperty.Name & @CRLF
   ;$Output &= $objProperty.Name & ": " & $objItem.AdminPasswordStatus  & @CRLF
  Next
Else
  MsgBox(0, "WMI Output", "No WMI records found for class: " & $strClass)
EndIf
$Output &= @crlf & " *** " & @CRLF
Next
MsgBox(0, "", $Output)

Share this post


Link to post
Share on other sites



I'm at the same point, I can use a variable for the class (e.g Win32_Bios) but I can't get the $objitem. & $var to work either, I pull in my session criteria from a session.tmp which contains classname,itemname,1 the one denotes that it's a select audit item in my console app.

so if you make any headway on this I'd be interested as well


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

Try this.

$Output &= $objProperty.Name & ": " & Execute("$objItem." & $objProperty.Name) & @CRLF

Adam

Share this post


Link to post
Share on other sites

Viva,

That's right, thank you.

I'm not so crazy after all, and you are an expert. ;)

With this optimal solution, I get a lot less lines of code. :graduated:

Sincerely

Nuno :)

Share this post


Link to post
Share on other sites

Thank you. I'm glad I could help.

Adam

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0