Get serial number from the extracted hwid.csv and use it to rename the csv file

1k views Asked by At

Hello Brilliant People,

Good day.

I may have a simple query here. The code below generates the hardware ID for Windows Autopilot and I am trying to rename it with the serial number of the machine.

Please let me know if this is possible.

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted
Set-Location D:\\HWID
.\Get-WindowsAutoPilotInfo.ps1 -OutputFile D:\HWID\AutoPilotHWID.csv

Just need to use the device serial number and output it as the filename :)

Device Serial Number,Windows Product ID,Hardware Hash
BXA6379CYA,,T0HuAgEAHAAAAAoAfwRhSgAACgAIBWFKA9ryKSACCQUCABAACQABAAIABAABAAAABQAZABAAAAAAAAAAEAAAAAAAAAACAAEAAwMAEQBHZW51aW5lSW50ZWwABAA0AEludGVsKFIpIENvcmUoVE0pIGk1LTQzMDBVIENQVSBAIDEuO

Appreciate the response.

1

There are 1 answers

0
Santiago Squarzon On BEST ANSWER

You can use Rename-Item to rename a file and Import-Csv to get the Serial from your CSV:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted
Set-Location D:\\HWID
.\Get-WindowsAutoPilotInfo.ps1 -OutputFile D:\HWID\AutoPilotHWID.csv
$serial = (Import-Csv D:\HWID\AutoPilotHWID.csv).'Device Serial Number' | Select-Object -First 1
Rename-Item -LiteralPath D:\HWID\AutoPilotHWID.csv -NewName ($serial + '.csv')