Powershell“加入”

前端之家收集整理的这篇文章主要介绍了Powershell“加入”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
叫我愚蠢,但我正在用这个丢我的头发.

我有两个Get-WmiObject的结果:

$cpu = Get-WmiObject -Class Win32_Processor 
$mb = Get-WmiObject -Class Win32_BaseBoard

现在,我可以从每个过滤和输出CSV文件

$cpu | Select-Object Name,Description | ConvertTo-Csv -NoTypeInformation

$mb | Select-Object Manufacturer,Product | ConvertTo-Csv -NoTypeInformation

但是,我可以加入这两个输出,并从两个CSV文件输出一个CSV输出?就像是:

( 
  ($cpu | Select-Object Name,Description) + 
  ($mb | Select-Object Manufacturer,Product) 
) | ConvertTo-Csv -NoTypeInformation

(当然这个语法是无效的,只是为了显示点)

解决方法

您需要Powershell V2以下.
$cpu = Get-WmiObject -Class Win32_Processor 
$mb = Get-WmiObject -Class Win32_BaseBoard
$props = @{            
    Name          = $cpu.Name
    Description   = $cpu.Description
    Manufacturer  = $mb.Manufacturer
    Product       = $mb.Product
    }
New-Object PSObject -Property $props | ConvertTo-Csv -NoTypeInformation

猜你在找的MsSQL相关文章