-
Notifications
You must be signed in to change notification settings - Fork 95
/
Get-Monitor.ps1
119 lines (109 loc) · 4.31 KB
/
Get-Monitor.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# https://www.reddit.com/r/PowerShell/comments/4qbvbp/get_serial_number_make_and_model_from_attached/
# alternative
# $Monitors = Get-WmiObject -Class Win32_PnPEntity | Where-Object Service -eq "Monitor"
# https://www.reddit.com/r/PowerShell/comments/6io2ws/check_how_many_monitors_are_connected/
function Get-Monitor {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[String[]]$ComputerName = $env:ComputerName
)
# List of Manufacture Codes that could be pulled from WMI and their respective full names. Used for translating later down.
$ManufacturerHash = @{
AAC = 'AcerView'
ACR = 'Acer'
AOC = 'AOC'
AIC = 'AG Neovo'
APP = 'Apple Computer'
AST = 'AST Research'
AUO = 'Asus'
BNQ = 'BenQ'
CMO = 'Acer'
CPL = 'Compal'
CPQ = 'Compaq'
CPT = 'Chunghwa Pciture Tubes, Ltd.'
CTX = 'CTX'
DEC = 'DEC'
DEL = 'Dell'
DPC = 'Delta'
DWE = 'Daewoo'
EIZ = 'EIZO'
ELS = 'ELSA'
ENC = 'EIZO'
EPI = 'Envision'
FCM = 'Funai'
FUJ = 'Fujitsu'
FUS = 'Fujitsu-Siemens'
GSM = 'LG Electronics'
GWY = 'Gateway 2000'
HEI = 'Hyundai'
HIT = 'Hyundai'
HSL = 'Hansol'
HTC = 'Hitachi/Nissei'
HWP = 'HP'
IBM = 'IBM'
ICL = 'Fujitsu ICL'
IVM = 'Iiyama'
KDS = 'Korea Data Systems'
LEN = 'Lenovo'
LGD = 'Asus'
LPL = 'Fujitsu'
MAX = 'Belinea'
MEI = 'Panasonic'
MEL = 'Mitsubishi Electronics'
MS_ = 'Panasonic'
NAN = 'Nanao'
NEC = 'NEC'
NOK = 'Nokia Data'
NVD = 'Fujitsu'
OPT = 'Optoma'
PHL = 'Philips'
REL = 'Relisys'
SAN = 'Samsung'
SAM = 'Samsung'
SBI = 'Smarttech'
SGI = 'SGI'
SNY = 'Sony'
SRC = 'Shamrock'
SUN = 'Sun Microsystems'
SEC = 'Hewlett-Packard'
TAT = 'Tatung'
TOS = 'Toshiba'
TSB = 'Toshiba'
VSC = 'ViewSonic'
ZCM = 'Zenith'
UNK = 'Unknown'
_YV = 'Fujitsu'
}
# Takes each computer specified and runs the following code:
foreach ($Computer in $ComputerName) {
# Grabs the Monitor objects from WMI
$Monitors = Get-WmiObject -Namespace root\WMI -Class WMIMonitorID -ComputerName $Computer -ErrorAction SilentlyContinue
# Takes each monitor object found and runs the following code:
foreach ($Monitor in $Monitors) {
# Grabs respective data and converts it from ASCII encoding and removes any trailing ASCII null values
$Mon_Model = try{ ([System.Text.Encoding]::ASCII.GetString($Monitor.UserFriendlyName)).Replace([string][char]0x0000, '') }catch{}
$Mon_Serial_Number = ([System.Text.Encoding]::ASCII.GetString($Monitor.SerialNumberID)).Replace([string][char]0x0000, '')
$Mon_Attached_Computer = ($Monitor.PSComputerName).Replace([string][char]0x0000, '')
$Mon_Manufacturer = ([System.Text.Encoding]::ASCII.GetString($Monitor.ManufacturerName)).Replace([string][char]0x0000, '')
<# Filters out "non monitors". Place any of your own filters here. These two are all-in-one computers with built in displays. I don't need the info from these.
if ($Mon_Model -like '*800 AIO*' -or $Mon_Model -like '*8300 AiO*') {
break
}#>
# Sets a friendly name based on the hash table above. If no entry found sets it to the original 3 character code
$Mon_Manufacturer_Friendly = $ManufacturerHash.$Mon_Manufacturer
if ($Mon_Manufacturer_Friendly -eq $null) {
$Mon_Manufacturer_Friendly = $Mon_Manufacturer
}
# Creates a custom monitor object and fills it with 4 NoteProperty members and the respective data
[pscustomobject]@{
Computer = $Mon_Attached_Computer
Manufacturer = $Mon_Manufacturer_Friendly
Model = $Mon_Model
SerialNumber = $Mon_Serial_Number
YearOfManufacture = $Monitor.YearOfManufacture
WeekOfManufacture = $Monitor.WeekOfManufacture
}
}
}
}