itdaddy
(Starting to like KiXtart)
2009-08-04 04:58 PM
help! looping a wmi kix? wt??

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!

 Quote:


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






eriqjaffe
(Hey THIS is FUN)
2009-08-04 06:47 PM
Re: help! looping a wmi kix? wt??

That class won't give you that information. Try this:

 Code:
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


itdaddy
(Starting to like KiXtart)
2009-08-04 08:45 PM
Re: help! looping a wmi kix? wt??

eriqjaffe

thanks you finally someone who knows what I need haha

hey I tried it and it is not working? I am using

wkix32.exe test1.kix
and it is not runing. I added

$Branch = "pc1", "pc2"

what am i doing wrong. did you test it yourself? does it work for you?
thank you


itdaddy
(Starting to like KiXtart)
2009-08-04 08:57 PM
Re: help! looping a wmi kix? wt??

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?
 Quote:


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







 Quote:


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


 Quote:


eriqjaffe
(Hey THIS is FUN)
2009-08-04 09:04 PM
Re: help! looping a wmi kix? wt??

Not sure why it's not working for you. The following:

 Code:
$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:

 Code:
PC Name: ERIQJ
UserName: DOMAIN\eriqj

PC Name: PC1
UserName: DOMAIN\amandak

PC Name: PC2
UserName: DOMAIN\juanc


itdaddy
(Starting to like KiXtart)
2009-08-04 09:18 PM
Re: help! looping a wmi kix? wt??

OMG I need to run it on a DOmain admin machine with domain admin
rights. duh!
Itw works yeah youa re a genius!

dude you are a genius it owrk perfect ;\) yeahooooooooooooo
thank you thankyou
as soon as I ran it on our DC it work fantatsic yeah!
you the man!
-robert


itdaddy
(Starting to like KiXtart)
2009-08-04 09:28 PM
Re: help! looping a wmi kix? wt??

hey I am using kix2exe gui and is there a wkix2exe?? i get compile errors
i want to package thsi program as an exe?


Glenn BarnasAdministrator
(KiX Supporter)
2009-08-04 09:36 PM
Re: help! looping a wmi kix? wt??

You should not need to run it from your DC. In fact, you should not run anything from your DC, for the sake of network security.

When you run admin scripts, you need to invoke them with admin rights. I've defined an environment variable called SUID on my workstation that contains the account name for my admin-privelege account. (ie SUID=SuperGlenn). Then, I have a little batch file called SUW.BAT that contains the following code:
 Code:
RunAs /profile /user:%SUID% cmd.exe
Opening a command prompt and typing SUW prompts me for my admin password. Once entered, it opens a new command prompt window with network admin rights, from where I can run any of my admin scripts.

Glenn


eriqjaffe
(Hey THIS is FUN)
2009-08-04 10:07 PM
Re: help! looping a wmi kix? wt??

 Originally Posted By: itdaddy
hey I am using kix2exe gui and is there a wkix2exe?? i get compile errors
i want to package thsi program as an exe?
You can choose whether you want to use kix32 or wkix32 in the kix2exe gui (look under "KiXtart Processor"). Just make sure that the wkix32 executable is in the \bin\kix path wherever you have kix2exe.