Scripts/Get-PCMonitor.ps1
Function Get-PCMonitor { <# .SYNOPSIS Get monitor information .DESCRIPTION Get monitor information .PARAMETER ComputerName The target computer name .EXAMPLE Get-PCMonitor -ComputerName LabPC2024 .NOTES N/A .LINK N/A #> [CmdletBinding ()] Param ( [Parameter (Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Enter computer name' ) ] [String[]]$ComputerName ) BEGIN { Function Show-Output ($Computer, $Values, $Status) { [PSCustomObject]@{ ComputerName = $Computer DeviceID = $Values.DeviceID Description = $Values.Description Manufacturer = $Values.MonitorManufacturer MonitorType = $Values.MonitorType PixelsPerXLogicalInch = $Values.PixelsPerXLogicalInch PixelsPerYLogicalInch = $Values.PixelsPerYLogicalInch ScreenWidth = $Values.ScreenWidth ScreenHeight = $Values.ScreenHeight Status = $Status } } } PROCESS { ForEach ($Computer In $ComputerName) { If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { Try { $Data = Get-WmiObject Win32_DesktopMonitor -ComputerName $Computer | Select-Object * ForEach ($Item In $Data) { Show-Output $Computer.ToUpper() $Item 'Ok' } } Catch { Show-Output $Computer.ToUpper() $Null $PSItem.Exception.Message } } Else { Show-Output $Computer.ToUpper() $Null 'Unreachable' } } } END {} } |