Hi,
Asking this question here because my previous one is awaiting moderator review :(
We have users using more than 2 monitors at work and we need to collect the monitor information for them and append to a csv. I have the below script:
$query = "Select * from WmiMonitorID"
if ($objWmi -isnot [system.array]) { $objWmi = @($objWmi) }
$objWmi = Get-WmiObject -Query $query -namespace root\WMI -ComputerName $env:COMPUTERNAME -ErrorAction SilentlyContinue
$CSVFile = "C:\Users\user\Desktop\computer1.csv"
Function ConvertTo-Char
(
$Array
)
{
$Output = ""
ForEach($char in $Array)
{ $Output += [char]$char -join ""
}
return $Output
}
$Results = ForEach ($Monitor in $objWmi)
{
New-Object PSObject -Property @{
UserFriendlyName = ConvertTo-Char($Monitor.userfriendlyname)
SerialNumber = ConvertTo-Char($Monitor.serialnumberid)
}
}
$Results | Select-Object UserFriendlyName | Export-Csv -Path $CSVFile -Append -Force
I get the output as below:

What I want to achieve is an output as below:

So for each users's $env:COMPUTERNAME, the monitor names (userfriendlyname) will go into 1 column in csv and will need to be separated by commas.
I was trying to achieve this using arrays but haven't been able to work it out.
Can someone please help with this?
Thanks in advance.
P.S. : Sorry for creating a new post for this.