Hello friends, first time poster here
.
I am trying to “normalize” the output of my function so it reads like:
| ComputerName | Model | MonitorModel | MonitorSerial |
| ABC123456 | HP ZBook | LG QHD | 361343 |
| ABC123456 | HP ZBook | D3218HN | X9R5K78200GE |
| ABC123567 | Surface Book | TDM13056 | 94441728 |
However, it is currently outputting like this:
| ComputerName | Model | MonitorModel | MonitorSerial |
| ABC123456 | HP ZBook | D3218HN | X9R5K78200GE |
| ABC123567 | Surface Book | TDM13056 | TDM1305694441728 |
# Adapted from https://powershell.org/forums/topic/monitor-serial-numbers-of-remote-machines-from-text-file/
function Get-Monitor {
[CmdletBinding()]
param (
[Parameter(
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[String[]]$ComputerName = '.'
)
begin
{
$inventory = New-Object -TypeName PSObject
}
process
{
foreach ($Computer in $ComputerName)
{
$ComputerSystemInfo = Get-CimInstance -Class win32_computersystem -ComputerName $Computer
$MonitorInfo = Get-CimInstance -Namespace root\wmi -Class WmiMonitorID -ComputerName $Computer
$props = [ordered]@{
'ComputerName' = $ComputerSystemInfo.Name
'Model' = $ComputerSystemInfo.Model
}
$inventory | Add-Member -NotePropertyMembers $props -Force
foreach ($monitor in $MonitorInfo)
{
$inventory | Add-Member -MemberType NoteProperty -Name 'MonitorModel' -Value ([system.text.encoding]::ascii.GetString($monitor.UserFriendlyName)) -Force
$inventory | Add-Member -MemberType NoteProperty -Name 'MonitorSerial' -Value ([system.text.encoding]::ascii.GetString($monitor.SerialNumberid)) -Force
}
Write-output -InputObject $inventory
}
}
}