#195237 - 2009-08-04 04:58 PM
help! looping a wmi kix? wt??
|
itdaddy
Starting to like KiXtart
Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
|
Hey guys what am I doing wrong? I want to have my code loop thru and array...how do I do that with wmi? I am looking for the wmi object that can give me pcname and locally loggedon person...man is it hard to find these attributes that match the object class???help do you guys know which object class has the pcname and locally logged on person? that is all I need grrrr help!
Break On $Branch = "emsr8", "emsr7"
For each $Element in $Branch $strComputer = $Element $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_Account",,48) For each $objItem in $colItems "Caption: " + $objItem.Caption ? "Description: " + $objItem.Description ? "Domain: " + $objItem.Domain ? "InstallDate: " + $objItem.InstallDate ? "LocalAccount: " + $objItem.LocalAccount ? "Name: " + $objItem.Name ? "SID: " + $objItem.SID ? "SIDType: " + $objItem.SIDType ? "Status: " + $objItem.Status ? ? Next Next
_________________________
Robert A+, CCNA, MCP Network Admin Credit Union Wisconsin
|
Top
|
|
|
|
#195238 - 2009-08-04 06:47 PM
Re: help! looping a wmi kix? wt??
[Re: itdaddy]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
That class won't give you that information. Try this:
For each $Element in $Branch
$objWMIService = GetObject("winmgmts:\\" + $Element + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For each $objItem in $colItems
"PC Name: " + $objItem.Name ?
"UserName: " + $objItem.UserName ?
?
Next
Next
Edited by eriqjaffe (2009-08-04 06:49 PM)
|
Top
|
|
|
|
#195240 - 2009-08-04 08:57 PM
Re: help! looping a wmi kix? wt??
[Re: eriqjaffe]
|
itdaddy
Starting to like KiXtart
Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
|
This works but when I put in a pcname that is not the machine I am running this on, I get an error something ')' is not correct? blah blah I want to run this on a one machine and I want to have arrays like $Branch = "pc1", "pc2", "pc3"
how can I get to work in the below code?????? runnning it locally it works fine but I want to run remmote PCnames thru an array?
I Guess the question to ask is "Can I run remote pcnames through this code in a for each next loop to access the remote pcname and local user name? or does this work only for local pcnames? If I use the local pc name it works, but if I put in a pcname that is not the local machine name, it erros out? what am I doing wrong /???anyone thanks
Break On
$Element = "LOCALPCNAME"
$objWMIService = GetObject("winmgmts:\\" + $Element + "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For each $objItem in $colItems "PC Name: " + $objItem.Name ? "UserName: " + $objItem.UserName ? ? Next sleep 20
Edited by itdaddy (2009-08-04 09:04 PM)
_________________________
Robert A+, CCNA, MCP Network Admin Credit Union Wisconsin
|
Top
|
|
|
|
#195241 - 2009-08-04 09:04 PM
Re: help! looping a wmi kix? wt??
[Re: itdaddy]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
Not sure why it's not working for you. The following:
$Branch = @WKSTA,"PC1","PC2"
For each $Element in $Branch
$objWMIService = GetObject("winmgmts:\\" + $Element + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For each $objItem in $colItems
"PC Name: " + $objItem.Name ?
"UserName: " + $objItem.UserName ?
?
Next
Next
gives me the following output:
PC Name: ERIQJ
UserName: DOMAIN\eriqj
PC Name: PC1
UserName: DOMAIN\amandak
PC Name: PC2
UserName: DOMAIN\juanc
Edited by eriqjaffe (2009-08-04 09:05 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 284 anonymous users online.
|
|
|