0

Every time i run my powershell script my output comes into a csv file but i want it to come all on one line, how it works now is that for every monitor my computer info sits infront of every monitor info like this: Current State

but i just want my Nth monitorinfo to append behind the second one like this: The state i want it to be in

the code i use:

$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 ';'

So if i would have 3 monitors the 3rd monitor would have to append after the 2nd now on the same line

claeys
  • 53
  • 3
  • 11

1 Answers1

0

The following may do what you want:

$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
  }

}
AdminOfThings
  • 23,946
  • 4
  • 17
  • 27
  • Do you know how to run this script in the background without a prompt coming up? Can i use a function inside my powershellscript to do this? – claeys Mar 27 '19 at 13:40
  • See [How to run a PowerShell script without displaying a window](https://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window) for running a PowerShell script quietly. – AdminOfThings Mar 27 '19 at 13:59