Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<#
.SYNOPSIS
Helper function to set the monitor input.
.DESCRIPTION
Uses ControlMyMonitor.exe to adjust VPCCode 60 for your monitor input.
.EXAMPLE
Set-MonitorInputSource -InputSource HDMI
Switched to HDMI input
.EXAMPLE
Set-MonitorInputSource -InputSource DisplayPort
Switches to DisplayPort input
.PARAMETER InputSource
HDMI or DisplayPort
.LINK
https://www.nirsoft.net/utils/control_my_monitor.html
.LINK
https://johnstonsoftwaresolutions.com/2019/02/09/tip-switch-monitor-inputs-with-command-line/
.NOTES
ControlMyMonitor.exe does not support dynamically retrieving a lot of info.
So, you will need to open ControlMyMonitor.exe and determine the names of your monitors.
They should look something like: \\.\DISPLAY1\Monitor0
Plug your monitor names into the $monitors array below.
You may also have to fiddle with the settings of your input numbers.
These will different between make/model and the connections you are using.
#>
function Set-MonitorInputSource {
[CmdletBinding()]
param(
[ValidateSet('HDMI', 'DisplayPort')]
[string]$InputSource
)
$ExePath = "$env:USERPROFILE\AppData\Local\ControlMyMonitor.exe"
if (Test-Path $ExePath) {
$InputSourceHash = @{
'DisplayPort' = 15 #differs depending on monitor brand/model and connection
'HDMI' = 17 #differs depending on monitor brand/model and connection
}
$monitors = @(
# you may have 1 or more monitors listed here
'\\.\DISPLAY1\Monitor0',
'\\.\DISPLAY2\Monitor0',
'\\.\DISPLAY3\Monitor0'
)
foreach ($monitor in $monitors) {
$argList = @(
'/SetValue'
$monitor
'60'
$InputSourceHash[$InputSource]
)
$argList
Start-Process -FilePath $ExePath -ArgumentList $argList -Wait
}
}
else {
Write-Warning "Unable to locate ControlMyMoniror.exe at: [$ExePath]"
}
}#Set-MonitorInputSource
<#
.SYNOPSIS
Helper function to get VPC values from your monitor.
.DESCRIPTION
Uses ControlMyMonitor.exe to retrieve VPCCode values from your monitor.
.EXAMPLE
Get-MonitorVPCValue -VPCCode 60
Returns value for VPC Code 60 - which is monitor input
.EXAMPLE
Get-MonitorVPCValue -VPCCode 10
Returns value for VPC Code 10 - which is monitor brightness level
.PARAMETER VPCCode
VPC Code number
.LINK
https://www.nirsoft.net/utils/control_my_monitor.html
.LINK
https://johnstonsoftwaresolutions.com/2019/02/09/tip-switch-monitor-inputs-with-command-line/
.NOTES
Open ControlMyMonitor.exe to determine what VPC Codes you can query.
#>
function Get-MonitorVPCValue {
[CmdletBinding()]
param(
[string]$VPCCode
)
$ExePath = "$env:USERPROFILE\AppData\Local\ControlMyMonitor.exe"
$argList = @(
'/GetValue'
'\\.\DISPLAY1\Monitor0'
$VPCCode
)
$p = Start-Process -FilePath $ExePath -ArgumentList $argList -Wait -PassThru
return $p.ExitCode
}#Get-MonitorVPCValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment