Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WMI calls problem

44 views
Skip to first unread message

Alan

unread,
May 5, 2007, 12:39:01 PM5/5/07
to
Hello,

I am trying to gather Serial Numbers, Install Dates, and Servers name for a
list of servers in my production environment. I have run into several snags
and I need help!

1) The wmi query to gather the information above is in two different
classes. So for each server I need to be able to query the win32_bios, and
win32_OperatingSystems classes.

2) I need to be able to merge the data into one table and output to a csv
file.

3) In my script I need to be able to use an array or variable so my for each
loop will take input from a txt file. (servers.txt)

So far I have not been very successful on any attempt. I was able to do one
call at a time but have not been able to get anything else to work. This
will not cut it for me because I need to query 530 servers.

Any help would be appreciated.

Thanks,

Alan

IJuan

unread,
May 5, 2007, 5:03:00 PM5/5/07
to
Try something like this:

$computers = Get-Content Servers.txt
Out-File Servers.csv -inputObject "Name, SN, Install"
foreach ($computer in $computers) {
$winBios = Get-WMIObject Win32_Bios -Computer $computer
$winOS = Get-WMIObject Win32_OperatingSystem
$sn = $winBios.SerialNumber
$install = $winOS.InstallDate
Out-File Servers.csv -inputObject "$computer, $sn, $install" -noClobber
}


-= IJuan =-

IJuan

unread,
May 5, 2007, 5:13:00 PM5/5/07
to
Or a oneliner like this.

gc servers.txt | % {out-file servers.csv -inputobject ("$_, " + (gwmi
Win32_Bios -computer $_).SerialNumber + ", " + (gwmi Win32_OperatingSystem
-computer $_).InstallDate)}

By the way I haven't tested either of these so there may be some typo or
type mismatch errors. Hope they at least get you pointed in the right way.


-= IJuan =-

Alan

unread,
May 5, 2007, 5:49:00 PM5/5/07
to
Thank you for both inputs. I will test them on Monday and post my findings.
This is exactly what I was looking for!
0 new messages