|
| 1 | +[CmdletBinding(DefaultParameterSetName = "UserDefined")] |
| 2 | +param( |
| 3 | + [Parameter(Mandatory, Position = 0, ParameterSetName = "UserDefined")] |
| 4 | + [ValidateSet("100", "125", "150", "175", "200", "225", "250", "300", "350", "400", "450", "500")] |
| 5 | + [int]$scale, |
| 6 | + |
| 7 | + [Parameter(Mandatory, ParameterSetName = "Recommended")] |
| 8 | + [switch]$reset |
| 9 | +) |
| 10 | + |
1 | 11 | # Self-elevate the script if required
|
2 | 12 | if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
|
3 |
| - if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { |
4 |
| - $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments |
5 |
| - Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine |
6 |
| - Exit |
7 |
| - } |
8 |
| -} |
9 |
| - |
10 |
| -$repoName = "PSGallery" |
11 |
| -$moduleName1 = "DisplayConfig" |
12 |
| -$moduleName2 = "MonitorConfig" |
13 |
| -if (!(Get-PSRepository -Name $repoName) -OR !(Find-Module -Name $moduleName1 | Where-Object {$_.Name -eq $moduleName1}) -OR !(Find-Module -Name $moduleName2 | Where-Object {$_.Name -eq $moduleName2})) { |
14 |
| - & .\dep_fix.ps1 |
| 13 | + if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { |
| 14 | + $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " |
| 15 | + $MyInvocation.BoundParameters.GetEnumerator() | ForEach-Object { $CommandLine += "-$($_.Key):$($_.Value) " } |
| 16 | + Start-Process -WorkingDirectory $PSScriptRoot -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine |
| 17 | + exit |
| 18 | + } |
15 | 19 | }
|
16 | 20 |
|
| 21 | +# Install dependencies if required. |
| 22 | +. "$PSScriptRoot\set-dependencies.ps1" |
17 | 23 |
|
18 |
| -# Import the local module |
19 |
| -$dpth = Get-Module -ListAvailable $moduleName1 | select path | Select-Object -ExpandProperty path |
20 |
| -import-module -name $dpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false |
| 24 | +# Getting the correct display |
| 25 | +$disp = Get-DisplayInfo | Where-Object { $_.DisplayName -eq "VDD by MTT" } |
21 | 26 |
|
22 |
| -# Import the other localmodule |
23 |
| -$mpth = Get-Module -ListAvailable $moduleName2 | select path | Select-Object -ExpandProperty path |
24 |
| -import-module -name $mpth -InformationAction:Ignore -Verbose:$false -WarningAction:SilentlyContinue -Confirm:$false |
25 |
| - |
26 |
| -# Check if there are enough arguments |
27 |
| -$numArgs = $args.Count |
28 |
| -switch ($numArgs) { |
29 |
| - 0 { Write-Error "This script requires a scale 'reset' or an accepted percfentage value (100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500) limited by the device max scale."; break } |
30 |
| - 1 { $disp = Get-Monitor | Select-String -Pattern "MTT1337" | Select-Object LineNumber | Select-Object -ExpandProperty LineNumber |
31 |
| - $maxscale = Get-DisplayScale -DisplayId $disp | Select-Object -ExpandProperty MaxScale |
32 |
| - if ( $args[0] -is [int] ) { |
33 |
| - if ( $args[0] -le $maxscale -And $args[0] -ge 100 ) { |
34 |
| - Set-DisplayScale -DisplayId $disp -Scale $args[0] |
35 |
| - break |
36 |
| - } |
37 |
| - else { |
38 |
| - Write-Error "Invalid scale percentage." |
39 |
| - break |
40 |
| - } |
41 |
| - } |
42 |
| - else { |
43 |
| - if ( $args[0] -eq "reset" ) { |
44 |
| - Set-DisplayScale -DisplayId $disp -Recommended |
45 |
| - break |
46 |
| - } |
47 |
| - else { |
48 |
| - Write-Error "Invalid arguments: 'reset' or a valid percentage value like 150 is acceptable." |
49 |
| - break |
50 |
| - } |
51 |
| - } |
| 27 | +$maxscale = Get-DisplayScale -DisplayId $disp.DisplayId | Select-Object -ExpandProperty MaxScale |
| 28 | +if ( $PSCmdlet.ParameterSetName -eq "UserDefined" ) { |
| 29 | + Write-Host "Setting scale to $scale" |
| 30 | + if ( $scale -le $maxscale ) { |
| 31 | + Set-DisplayScale -DisplayId $disp.DisplayId -Scale $scale |
| 32 | + } |
| 33 | + else { |
| 34 | + Write-Error "Scale percentage $scale is higher than max scale $maxscale" |
52 | 35 | }
|
53 |
| - default { Write-Error "Invalid number of arguments: $numArgs"; break } |
| 36 | +} |
| 37 | +elseif ( $PSCmdlet.ParameterSetName -eq "Recommended" ) { |
| 38 | + Set-DisplayScale -DisplayId $disp.DisplayId -Recommended |
| 39 | +} |
| 40 | +else { |
| 41 | + Write-Error "Invalid arguments: 'reset' or a valid percentage value like 150 is acceptable." |
54 | 42 | }
|
0 commit comments