Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI overload! Okay next question.

Status
Not open for further replies.
Feb 11, 2005
153
US
I now have my WMI query for the patch setup! Now I was asked to do something I am unfamiliar with.

I have a list of Machine Names compiled from AD, I have a list of MB serial numbers.

I know WMI_Bios holds the serial number in the SerialNumber number field. Is there any way I make the query aginst a list of serial numbers?

What I need is to get all computers in AD that have a bank serial number OR are on the list of serial numbers I was given

E.G. something like -

Set colSerialNumber = objWMIService.ExecQuery _
("Select SerialNumber from Win32_Bios Where SerialNumber = 'Some list?'")
If colHotfix.Count = 0 Then
objFileOutput.WriteLine strDeviceName & ",This computer has no programmed serial number."

The other thing is I need this same query to also give me back the last logged on user so we can try and locate the PC.

The question there is can I get the Last logged on user in the same query as the bios to have a single output line?

Something like -
("Select SerialNumber from Win32_Bios AND Username from Win32_ComputerSystem Where SerialNumber = 'Some list?'")

I know this is getting too complex for me as I am not familiar with WMI querying.

Basically I need 3 things - Machine name (one on our domain), last logged on user, and serial number off list I have OR a blank serial number (as the blank ones we have to go program).

Thanks for putting up with me guys your helping me learn alot about VBScripting and its uses. I now have a library of over 40 scripts developed and were running a good 10 of them almost weekly in production :)

Yeay you!
 
I would take the serial number list and add to a dictionary. Then take the computer names and query them for the serial number. Do something like

Set colSerialNumber = objWMIService.ExecQuery _
("Select SerialNumber from Win32_Bios")
For Each strSerial in colSerialNumbers
If objDict.Exists(strSerial) Then
'do something
Else
'need to get a serial
End If
Next

As for the second query you posted, you can't do that in that manner. Both classes are associated, but I'm not sure if that would allow you to get the information you want in one shot. It is easier to do it separately.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
get the pc's to update an attribute in AD when they are turned on?
 
Nah can't modify AD we don't have rights to do anything of that nature.

I also decided to err on too much data than not enough so I did this -

Code:
Set colSerialNumber = objWMIService.ExecQuery _
("Select SerialNumber from Win32_Bios")

If colSerialNumber.Count = 0 Then 
 Set colLoggedInUser = objWMIService.ExecQuery _
   ("Select UserName from Win32_ComputerSystem")
       If colLoggedInUser.Count = 0 Then 
          objFileOutput.WriteLine strDeviceName & ",,This machine has no serial number or last logged on information."
       Else
        For Each objLoggedInUser in colLoggedInUser
           objFileOutput.WriteLine strDeviceName & ",," & objLoggedInUser & "
         Next
        End if 
 Else
 For Each objSerialNumber in colSerialNumber
     Set colLoggedInUser = objWMIService.ExecQuery _
   ("Select UserName from Win32_ComputerSystem")
       If colLoggedInUser.Count = 0 Then 
          objFileOutput.WriteLine strDeviceName & "," & objSerialNumber & ","
       Else
        For Each objLoggedInUser in colLoggedInUser
           objFileOutput.WriteLine strDeviceName & "," & objSerialNumber & "," & objLoggedInUser & "
         Next
        End if 
   Next

It works well but the reporting is all off I am going to start a new thread on this question but it seems these "nested" wmi queries work okay.
 
I may be wrong, but looking at your queries, I don't think you will get any of those counts to equal 0 even if the value you're looking for is empty.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
You should keep the thread rather than open a new. Those obj... are object and you must get their appropriate property to write to the file.
[tt]
Set colSerialNumber = objWMIService.ExecQuery _
("Select SerialNumber from Win32_Bios")
Set colLoggedInUser = objWMIService.ExecQuery _
("Select UserName from Win32_ComputerSystem")

select case true
case (colSerialNumber.count=0) and (colLoggedInUser.count=0)
objFileOutput.WriteLine strDeviceName & ",,This machine has no serial number or last logged on information."
case (colSerialNumber=0)
objFileOutput.WriteLine strDeviceName & ",," & objLoggedInUser.username
case (colLoggedInUser=0)
objFileOutput.WriteLine strDeviceName & "," & objSerialNumber.serialnumber & ","
case else
objFileOutput.WriteLine strDeviceName & "," & objSerialNumber.serialnumber & "," & objLoggedInUser.username
end select
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top