我一直在尝试将以下脚本导出到csv文件。我对Powershell很新。非常感谢任何帮助。
# get-content H:\src\win\hostlist.txt | % {
# @("dsp021","dsp075") | % {
@("dsp075") | % {
write "Name, Manufacturer, Model"
gwmi win32_computersystem -ComputerName $_ | select -Property Manufacturer, Model, Name
gwmi win32_computersystemproduct -ComputerName $_ | select uuid
write "mac addresses:"
gwmi win32_networkadapter -ComputerName $_ | ? { $_.MACAddress -match ":" } | select MACAddress
write "Solarflare network IDs"
gwmi win32_pnpentity -ComputerName $_ | ? { $_.Manufacturer -match "Solar"} | Select Name,DeviceID
write "LSI Disk controller IDs"
gwmi win32_pnpentity -ComputerName $_| ? { $_.Manufacturer -match "LSI"} | Select Name,DeviceID
} |Format-list
谢谢!
答案 0 :(得分:1)
我修改了您的代码,以便将其导出为CSV文件。 我不确定这是否是你想要的格式,但它应该给你一个想法。
@("computername") | % {
gwmi win32_computersystem -ComputerName $_ | select -Property Manufacturer, Model, Name | ConvertTo-Csv -NoTypeInformation
gwmi win32_computersystemproduct -ComputerName $_ | select uuid | ConvertTo-Csv -NoTypeInformation
#write "mac addresses:"
gwmi win32_networkadapter -ComputerName $_ | ? { $_.MACAddress -match ":" } | select @{Name="Mac Addresses";Expression={$_."MACAddress"}} | ConvertTo-Csv -NoTypeInformation
#write "Solarflare network IDs"
gwmi win32_pnpentity -ComputerName $_ | ? { $_.Manufacturer -match "Solar"} | Select @{Name="Solarflare network Names";Expression={$_."Name"}} ,@{Name="Device IDs";Expression={$_."DeviceID"}} | ConvertTo-Csv -NoTypeInformation
#write "LSI Disk controller IDs"
gwmi win32_pnpentity -ComputerName $_| ? { $_.Manufacturer -match "LSI"} | Select @{Name="LSI Disk controller Names";Expression={$_."Name"}} ,@{Name="Device IDs";Expression={$_."DeviceID"}} |ConvertTo-Csv -NoTypeInformation
} | out-file C:\works.csv
脚本将所有命令输出转换为CSV,然后将所有命令导出到文件中。