PowerShell是否将多个变量导出到csv?

PowerShell是否将多个变量导出到csv?,powershell,csv,Powershell,Csv,一般资料 $ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem | Select -Property Model , Manufacturer , Description , PrimaryOwnerName , SystemType $BIOS = Get-WmiObject -Class Win32_BIOS | Select -Property PSComputerName , Manufacturer , Version

一般资料

$ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem | Select -Property Model , Manufacturer , Description , PrimaryOwnerName , SystemType
$BIOS = Get-WmiObject -Class Win32_BIOS | Select -Property PSComputerName , Manufacturer , Version #| Export-Csv -InputObject 
$OS = Get-WmiObject -Class Win32_OperatingSystem | Select -Property Caption , CSDVersion , OSArchitecture , OSLanguage  
启动配置

$BootConfiguration = Get-WmiObject -Class Win32_BootConfiguration | Select -Property Name , ConfigurationPath 
BIOS信息

$ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem | Select -Property Model , Manufacturer , Description , PrimaryOwnerName , SystemType
$BIOS = Get-WmiObject -Class Win32_BIOS | Select -Property PSComputerName , Manufacturer , Version #| Export-Csv -InputObject 
$OS = Get-WmiObject -Class Win32_OperatingSystem | Select -Property Caption , CSDVersion , OSArchitecture , OSLanguage  
操作系统信息

$ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem | Select -Property Model , Manufacturer , Description , PrimaryOwnerName , SystemType
$BIOS = Get-WmiObject -Class Win32_BIOS | Select -Property PSComputerName , Manufacturer , Version #| Export-Csv -InputObject 
$OS = Get-WmiObject -Class Win32_OperatingSystem | Select -Property Caption , CSDVersion , OSArchitecture , OSLanguage  

我想将所有这些变量导出到带有标题的csv文件中,但我无法。

以下内容将get wmiobject命令分别创建的每个对象的noteproperties合并到$report变量中。从那里您可以导出到csv

通过遍历gwmi调用创建的每个变量并将noteproperties添加到报表变量中的循环,可以更好地简化这一过程

$ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem | Select -Property Model , Description , PrimaryOwnerName , SystemType
$BootConfiguration = Get-WmiObject -Class Win32_BootConfiguration | Select -Property Name , ConfigurationPath 
$BIOS = Get-WmiObject -Class Win32_BIOS | Select -Property PSComputerName , Manufacturer , Version 
$OperatingSystem = Get-WmiObject -Class Win32_OperatingSystem | Select -Property Caption , CSDVersion , OSArchitecture , OSLanguage  

$report = New-Object psobject
$report | Add-Member -MemberType NoteProperty -name Model -Value $ComputerSystem.Model
$report | Add-Member -MemberType NoteProperty -name Description -Value $ComputerSystem.Description
$report | Add-Member -MemberType NoteProperty -name PrimaryOwnerName -Value $ComputerSystem.PrimaryOwnerName
$report | Add-Member -MemberType NoteProperty -name SystemType -Value $ComputerSystem.SystemType
$report | Add-Member -MemberType NoteProperty -name Name -Value $BootConfiguration.Name
$report | Add-Member -MemberType NoteProperty -name ConfigurationPath -Value $BootConfiguration.ConfigurationPath
$report | Add-Member -MemberType NoteProperty -name PSComputerName -Value $BIOS.PSComputerName
$report | Add-Member -MemberType NoteProperty -name Manufacturer -Value $BIOS.Manufacturer
$report | Add-Member -MemberType NoteProperty -name Version -Value $BIOS.Version
$report | Add-Member -MemberType NoteProperty -name Caption -Value $OS.Caption
$report | Add-Member -MemberType NoteProperty -name CSDVersion -Value $OS.CSDVersion
$report | Add-Member -MemberType NoteProperty -name OSArchitecture -Value $OS.OSArchitecture
$report | Add-Member -MemberType NoteProperty -name OSLanguage -Value $OS.OSLanguage

$report | export-csv .\file.csv -NoTypeInformation

创建一个自定义对象,该对象包含csv文件中所需的所有属性,并通过管道将其导出为类似于kohlbrr SuggestThink的csv文件的结构-这将使事情更清楚(手动编写一个带有列标题和示例内容的示例文件)。两个变量具有制造商属性。