I'm new to PowerShell and I try to read some monitor/display infos from clients.
I put together this script:
param(
[string]$ComputerName
)
$objWMi = get-wmiobject -namespace root\WMI -ComputerName $ComputerName -class WmiMonitorID | select WeekOfManufacture, YearOfManufacture, UserFriendlyName, SerialNumberID, ManufacturerName
$Userfn = ForEach-Object {($objWMi.UserFriendlyName -ne 0 | foreach {[char]$_}) -join"";}
$SerialNum = ForEach-Object {($objWMi.SerialNumberID -ne 0 | foreach {[char]$_}) -join"";}
$ManuName = ForEach-Object {($objWMi.ManufacturerName -ne 0 | foreach {[char]$_}) -join"";}
$Weekom = $objWMi.WeekOfManufacture
$Yearom = $objWMi.YearOfManufacture
Write-Host "1: $Userfn | $ManuName | $SerialNum | $Weekom | $Yearom"
Exit 0
It is called with .\myscript.ps1 -ComputerName clientdnsname and returns something like this:
1: P22W-5 ECO | FUS | YE7XXXXX | 46 | 2008.
Works like a charm, exactly what I need. There is one exception: if some client has more than one monitor attached the script returns something like this:
1: HP E272qHP E272q | HWPHWP | CNKXXXXCCNKYYYY | 40 40 | 2015 2015
How can I modify the output to split the result up if there is more than one monitor and output
1: HP E272q | HWP| CNKXXXX | 40 | 2015 2: HP E272q | HWP| CNKXXXX | 40 | 2015
The variables contain the infos for all monitors and I have no idea how to avoid this or how to split this up in one value per variable. Any ideas much appreciated!
EDIT: I need the result returned in one row like above because I feed this to another program.