I\'m currently studying Powershell and working on a script that grabs multi-monitors Display configuration from windows system. Thanks to the help from other guys, I finally wor
Put the partial results into variables and assemble all in one [PSCustomObject]
(I'm not quite sure if the order of the screens will match the MonitorID order)
The property InstanceName
which is common to both WmiMonitorID
and WmiMonitorconnectionparams
is used to sync the settings.
EDIT: incorporated mklement0's hint
EDIT2: added properties ProductCodeID,SerialNumberID,Manufactured(year,week)
## Q:\Test\2018\07\16\SO_51368476.ps1
##
enum VideoOutputTechnology {
UNINITIALIZED = -2
UNKNOW = -1
VGA = 0
S_VIDEO = 1
COMPOSITE_VIDEO = 2
COMPONENT_VIDEO = 3
DVI = 4
HDMI = 5
LVDS_OR_MIPI_DSI = 6
D_JPN = 8
SDI = 9
DISPLAYPORT_EXTERNAL = 10
DISPLAYPORT_EMBEDDED = 11
UDI_EXTERNAL = 12
UDI_EMBEDDED = 13
DONGLE_CABLE_THAT_SUPPORTS_SDTV = 14
MIRACAST_CONNECTED_SESSION = 15
INTERNAL_CONNECTION = 0x80000000
}
Add-Type -AssemblyName system.windows.forms
$Screens = [system.windows.forms.screen]::AllScreens.Bounds
$MIDs = Get-WmiObject WmiMonitorID -Namespace root\wmi
$i=0
$AllMonInfo = ForEach ($MID in $MIDs){
$MCP = (Get-WmiObject WmiMonitorconnectionparams -Namespace root\wmi |
Where-Object InstanceName -eq $MID.InstanceName)
[PSCustomObject]@{
Manufacturer = (-join [char[]] $MID.ManufacturerName)
Model = (-join [char[]] $MID.UserFriendlyName)
ProductCodeID= (-join [char[]] $MID.ProductCodeID)
SerialNumberID=(-join [char[]] $MID.SerialNumberID)
Manufactured = ("{0}W{1}" -f $MID.YearOfManufacture,$Mid.WeekOfManufacture.ToString('00'))
Width = $Screens[$i].Width
Height = $Screens[$i].Height
VideoOutput = ([VideoOutputTechnology]$MCP.VideoOutputTechnology)
}
$i++
}
$AllMonInfo | Format-List | Out-File '.\system1.txt' -Append -Encoding ascii
Sample output:
Get-Content '.\system1.txt'
Manufacturer : SAM
Model : SyncMaster
ProductCodeID : 03E7
SerialNumberID : H9XQxxxxxx
Manufactured : 2008W40
Width : 1920
Height : 1200
VideoOutput : DVI
Manufacturer : SAM
Model : SyncMaster
ProductCodeID : 0425
SerialNumberID : H1AKxxxxxx
Manufactured : 2008W10
Width : 1920
Height : 1200
VideoOutput : DVI