Reputation: 53
I want to save the serial number and the MAC address of each machine to a CSV file. I will use a USB drive to run the powershell file on each computers and save it on a CSV file. I use the script below:
$MAC = Get-NetAdapter -Name "Ethernet"
$serial = (Get-WmiObject Win32_Bios).SerialNumber
$dir = Set-Content "$location" -Value "Serial Number,MAC Address"
$dir
$location = "C:\Users\Frangon\Desktop\$env:COMPUTERNAME.csv"
Add-Content $location $serial
Add-Content $location $MAC.MacAddress
The result is this:
I want the MAC address to be on the MAC address column and vice versa.
This is the result of my noob script
Upvotes: 0
Views: 2739
Reputation: 6860
What you are talking about is creating a PSobject
. Also Export-Csv
New-object psobject -Property @{
"Serial Number" = $(Get-WmiObject Win32_Bios).SerialNumber
"Mac Address" = $(Get-NetAdapter -Name "Ethernet").MacAddress
} | Export-Csv -Path C:\ComputerDetials.csv -NoTypeInformation -Append
Upvotes: 1