Getting Serial Number of each computer in a list (Powershell)

I would like to get the serial numbers of a list of computers. I have created a powershell script as follows:


$computers = Get-Content c:\pstest\computerlist.txt

Get-wmiobject win32_bios | ForEach-Object {$_.serialnumber}

All I get is as follows:

PS C:\pstest> .\pstest01.ps1
R6Z00180

How do I do this ?

Answers


The ComputerName parameter accepts a collecion of names so you can pass the content of the file to it:

$computers = Get-Content c:\pstest\computerlist.txt
Get-wmiobject Win32_Bios -ComputerName $computers | Select-Object __SERVER, SerialNumber

Get-WmiObject has a -ComputerName parameter:

$computers | foreach { (Get-WmiObject Win32_BIOS -Computername $_).SerialNumber }

Elaborating on Shay's answer. If you insist to have everything in a single pipeline:

Get-WmiObject Win32_Bios -ComputerName (Get-Content c:\pstest\computerlist.txt) | 
Select-Object __SERVER, SerialNumber

Need Your Help