[英]Output Serial Number and MAC address on CSV file using powershell with 2 columns
I want to save the serial number and the MAC address of each machine to a CSV file. 我想将每台机器的序列号和MAC地址保存到CSV文件中。 I will use a USB drive to run the powershell file on each computers and save it on a CSV file.
我将使用USB驱动器在每台计算机上运行powershell文件,并将其保存在CSV文件中。 I use the script below:
我使用以下脚本:
$MAC = Get-NetAdapter -Name "Ethernet" $ MAC = Get-NetAdapter-名称“以太网”
$serial = (Get-WmiObject Win32_Bios).SerialNumber $ serial =(Get-WmiObject Win32_Bios).SerialNumber
$dir = Set-Content "$location" -Value "Serial Number,MAC Address" $ dir =设置内容“ $ location”-值“序列号,MAC地址”
$dir $ DIR
$location = "C:\\Users\\Frangon\\Desktop\\$env:COMPUTERNAME.csv" $ location =“ C:\\ Users \\ Frangon \\ Desktop \\ $ env:COMPUTERNAME.csv”
Add-Content $location $serial 添加内容$ location $ serial
Add-Content $location $MAC.MacAddress 添加内容$ location $ MAC.MacAddress
The result is this: 结果是这样的:
enter image description here 在此处输入图片说明
I want the MAC address to be on the MAC address column and vice versa. 我希望MAC地址在MAC地址列中,反之亦然。
What you are talking about is creating a PSobject
. 您正在谈论的是创建
PSobject
。 Also Export-Csv
还可以
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.