powershellcsvwmicserial-number

Get serialnumber from asset list


Started in recent weeks in a Junior infrastructure role, and begun playing around with powershell to help save some time here and there.

I am trying to do the following: 1- I'm port a CSV file with a single column names asset 2- Perform a "ForEach" check on each line to find the device's serial number 3- Output results to a CSV with two column "asset" and "serialnumber"

I have dabbled in a few areas, and am currently sitting at something like this:

$file1 = Import-Csv -path "c:\temp\assets.csv" | ForEach-Object {
$asset = $_.asset
}
wmic /node:$asset bios get serialnumber
Export-Csv -Path "c:\temp\assetandserial.csv" -NoTypeInformation

As you may or may not see, I tried to set the column labelled "asset" as the variable, however, not sure if I placed it correctly. I have tried a few other things, but honestly it's all new to me, so I haven't the foggiest idea where to go from here.


Solution

  • Get-CimInstance Win32_BIOS -ComputerName (Import-Csv c:\temp\assets.csv).asset | 
      Select-Object @{ n='Asset'; e='PSComputerName' }, SerialNumber |
      Sort-Object Asset |
      Export-Csv c:\temp\assetandserial.csv -NoTypeInformation