PoshCode Logo PowerShell Code Repository

Inventory Monitors by invd-dt-da16 8 weeks ago (modification of post by Adrian Rodriguez view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6753"></script>download | new post

  1. function Get-Monitor{
  2.     [cmdletbinding()]
  3.  
  4.     Param(
  5.         [Parameter(Mandatory=$True,Position=0)]
  6.         [string[]]$ComputerName
  7.     )
  8.  
  9.     Begin{}
  10.  
  11.     Process{
  12.         Foreach($Computer in $ComputerName){
  13.             If(Test-Connection -ComputerName $Computer -Count 1 -Quiet){
  14.                 Try{
  15.                     $Monitors = get-wmiobject -ComputerName $Computer -ClassName wmimonitorid -Namespace root/wmi -ErrorAction Stop
  16.                     Foreach($Monitor in $Monitors){
  17.                         $Model = [System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName)
  18.                         $SerialNumber = [System.Text.Encoding]::ASCII.GetString($Monitor.SerialNumberID)
  19.                         New-Object -TypeName PSCustomObject -Property @{
  20.                             ComputerName = $Computer
  21.                             Model = $Model
  22.                             SerialNumber = $SerialNumber
  23.                         }
  24.                     }
  25.                 }
  26.                 Catch{
  27.                     Write-Warning -Message "Cannot query WMIMonitorID WMI class on $Computer. $($_.Exception.Message)"
  28.                 }
  29.             }
  30.             Else{
  31.                 Write-Warning -Message "Connection to remote server $Computer failed."
  32.             }
  33.         }
  34.     }
  35.  
  36.     End{}
  37. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me