Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-Monitor{
- [cmdletbinding()]
- Param(
- [Parameter(Mandatory=$True,Position=0)]
- [string[]]$ComputerName
- )
- Begin{}
- Process{
- Foreach($Computer in $ComputerName){
- If(Test-Connection -ComputerName $Computer -Count 1 -Quiet){
- Try{
- $Monitors = get-wmiobject -ComputerName $Computer -Class wmimonitorid -Namespace root/wmi -ErrorAction Stop
- Foreach($Monitor in $Monitors){
- If($Monitor.UserFriendlyName -ne $null){$Model = [System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName)}
- Else{$Model = "N/A"}
- If($Monitor.SerialNumberID -ne $null){
- $SerialNumber = [System.Text.Encoding]::ASCII.GetString($Monitor.SerialNumberID)
- If($SerialNumber -eq 0){
- $SerialNumber = "N/A"
- }
- }
- Else{$SerialNumber = "N/A"}
- New-Object -TypeName PSCustomObject -Property @{
- ComputerName = $Computer
- Model = $Model
- SerialNumber = $SerialNumber
- }
- }
- }
- Catch{
- Write-Warning -Message "Cannot query WMIMonitorID WMI class on $Computer. $($_.Exception.Message)"
- }
- }
- Else{
- Write-Warning -Message "Connection to remote server $Computer failed."
- }
- }
- }
- End{}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement