每次我运行powershell脚本时,我的输出都会输出到一个csv文件中,但我希望它全部显示在一行上,现在它是如何工作的,因为对于每台显示器,我的计算机信息都位于每个显示器信息的前面,如下所示:
但是我只希望第N个monitorinfo像这样在第二个后面附加:
我使用的代码:
$output = foreach($computer in $Desktop){
ForEach ($Monitor in $Monitors){
$Manufacturer = ($Monitor.ManufacturerName -notmatch 0 | ForEach-Object{[char]$_}) -join ""
$Name = ($Monitor.UserFriendlyName -notmatch 0 | ForEach-Object{[char]$_}) -join ""
$Serial = ($Monitor.SerialNumberID -notmatch 0 | ForEach-Object{[char]$_}) -join ""
[PSCustomObject]@{
"Merk" = $Desktop.CsManufacturer
"Model" = $Desktop.CsModel
"S/n" = $Desktop | Select-Object -expand BiosSeralNumber
"PC Naam" = $Desktop.CsName
"CPU" = $processor.Name
"Memory" = "$RAM GB"
"OS" = $Desktop.WindowsProductName
"MAC LAN" = $MACLAN
"MAC WIFI" = $MACWIFI
"Office" = $officeVersion
"Merk /Model" = $Manufacturer
"Type" = $Name
"SerialScherm" = $Serial
}
}
}
$output | Export-Csv -Path $GL\info.csv -NoTypeInformation -Delimiter ';'
因此,如果我有3个监视器,则第3个监视器必须在第2个监视器之后追加到同一行
答案 0 :(得分:0)
以下内容可能会满足您的要求:
$output = foreach($computer in $Desktop){
$Hash = [ordered]@{ "Merk" = $Desktop.CsManufacturer
"Model" = $Desktop.CsModel
"S/n" = $Desktop | Select-Object -expand BiosSeralNumber
"PC Naam" = $Desktop.CsName
"CPU" = $processor.Name
"Memory" = "$RAM GB"
"OS" = $Desktop.WindowsProductName
"MAC LAN" = $MACLAN
"MAC WIFI" = $MACWIFI
"Office" = $officeVersion
}
$MonitorNumbers = @($null)
$MonitorNumbers += (2..$Monitors.count)
$MonitorIndex = 0
ForEach ($Monitor in $Monitors){
$Manufacturer = ($Monitor.ManufacturerName -notmatch 0 | ForEach-Object{[char]$_}) -join ""
$Name = ($Monitor.UserFriendlyName -notmatch 0 | ForEach-Object{[char]$_}) -join ""
$Serial = ($Monitor.SerialNumberID -notmatch 0 | ForEach-Object{[char]$_}) -join ""
$Hash.add("Merk /Model $($MonitorNumbers[$MonitorIndex])", $Manufacturer)
$Hash.add("Type $($MonitorNumbers[$MonitorIndex])", $Name)
$Hash.add("SerialScherm $($MonitorNumbers[$MonitorIndex])",$Serial)
$MonitorIndex++
}
[PSCustomObject]$Hash
}
}