Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Script to Change Monitor Orientation Using PowerShell

Script:

# Define the orientation options
$orientations = @{
    "0" = "Landscape"
    "1" = "Portrait"
    "2" = "Landscape (flipped)"
    "3" = "Portrait (flipped)"
}

# Prompt user for the desired orientation
Write-Host "Select the monitor orientation:"
$orientations.GetEnumerator() | ForEach-Object { Write-Host "$($_.Key): $($_.Value)" }
$selection = Read-Host "Enter the number corresponding to the desired orientation"

# Validate the selection
if (-not $orientations.ContainsKey($selection)) {
    Write-Host "Invalid selection. Exiting script."
    exit
}

# Use the DisplaySwitch.exe utility to change the orientation
$orientationValue = $selection
$monitorId = 0 # Default to the primary monitor, change if needed

# Use PowerShell command to change the orientation
# Note: This requires administrative privileges
$command = "DisplaySwitch.exe /internal"
Start-Process -FilePath $command -ArgumentList "/rotate:$orientationValue" -Verb RunAs

Write-Host "Monitor orientation changed to $($orientations[$selection])."

Como Executar o Script:

  1. Open PowerShell with administrative privileges. You can do this by searching for "PowerShell" in the Start menu, right-clicking it, and selecting "Run as administrator".

  2. Copy the script above into a new file and save it with a .ps1 extension, for example, ChangeMonitorOrientation.ps1.

  3. In the PowerShell window, navigate to the directory where you saved the script using the cd command.

  4. Execute the script by typing .\ChangeMonitorOrientation.ps1 and pressing Enter.

  5. Follow the on-screen instructions to select the desired monitor orientation by entering the corresponding number.

  6. The script will change the monitor orientation to the selected option.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.