Created
June 20, 2024 21:26
-
-
Save qcomer/95964632656b9a4e99e7aa9e2cccbd0b to your computer and use it in GitHub Desktop.
Set taskbar location to the left side of the screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| <Overview of script> | |
| .DESCRIPTION | |
| <Brief description of script> | |
| .NOTES | |
| Version: 0.1 | |
| Author: qcomer (https://github.com/qcomer) | |
| Last Modified: Thu Jun 20 2024 | |
| Modified By: qcomer | |
| Date Created: Thu Jun 20 2024 | |
| Filename: Win_Set-TaskBarLocation.ps1 | |
| RMMScriptName: | |
| RMMMonitorName: | |
| .INPUTS | |
| .OUTPUTS | |
| .EXAMPLE | |
| .LINK | |
| HISTORY: | |
| Date By Comments | |
| ---------- ---------- -------------------------------------------- | |
| #> | |
| #region Parameters | |
| Param( | |
| ) | |
| #endregion Parameters | |
| #region Variables | |
| #$script:FolderPath = [System.Environment]::GetEnvironmentVariable('TEMP', 'Machine') | |
| #endregion Variables | |
| #region Modules | |
| $installed = Get-Module -Name 'RunAsUser' -ListAvailable -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| $available = Find-Module -Name 'RunAsUser' | Select-Object -First 1 | |
| if ($null -eq $installed) { | |
| Install-Module -Name 'RunAsUser' -Force | |
| } elseif ($installed.version -lt $available.version) { | |
| Update-Module -Name 'RunAsUser' -Force | |
| } | |
| Import-Module -Name RunAsUser -Force | |
| #endregion Modules | |
| #region Functions | |
| #endregion Functions | |
| $scriptblock = { | |
| Function Set-TaskbarLocation { | |
| [CmdletBinding(SupportsShouldProcess, PositionalBinding, ConfirmImpact = 'High')] | |
| [OutputType([String])] | |
| Param ( | |
| [Parameter(Mandatory = $true, ValueFromPipeline = $True, Position = 0)] | |
| [ValidateSet('top', 'Left', 'bottom', 'right')] | |
| [String]$Location, | |
| [Parameter(mandatory = $false, valuefrompipeline = $true, position = 1)] | |
| [switch] | |
| $RestartExplorer | |
| ) | |
| Begin { | |
| $StartTime = '{0:MM/dd/yyyy HH:mm:ssZ}' -f (Get-Date) | |
| $calcStart = (Get-Date) | |
| Write-Verbose "[$($StartTime) BEGIN] Starting $($mycommand.myinvocation)" | |
| } | |
| Process { | |
| $Processtime = '{0:MM/dd/yyyy HH:mm:ssZ}' -f (Get-Date) | |
| Write-Verbose "[$($Processtime) PROCESS]" | |
| If ($PSCmdlet.ShouldProcess('Target', 'Operation')) { | |
| $bit = 0 | |
| switch ($location) { | |
| 'left' { | |
| $bit = 0x00 | |
| } | |
| 'right' { | |
| $bit = 0x02 | |
| } | |
| 'top' { | |
| $bit = 0x01 | |
| } | |
| 'bottom' { | |
| $bit = 0x03 | |
| } | |
| } | |
| $registryPath = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3' | |
| $Settings = (Get-ItemProperty -Path $registryPath -Name Settings).Settings | |
| $settings[12] = $bit | |
| Set-ItemProperty -Path $registryPath -Name Settings -Value $Settings | |
| if ($RestartExplorer -eq $true) { | |
| Get-Process -Name 'Explorer' | Stop-Process -Force | |
| } | |
| } | |
| } | |
| End { | |
| $EndTime = '{0:MM/dd/yyyy HH:mm:ssZ}' -f (Get-Date) | |
| $calcEnd = (Get-Date) | |
| $TotalTime = New-TimeSpan -Start $calcStart -End $calcEnd | |
| Write-Verbose "[$($EndTime) END] Ending $($mycommand.myinvocation). Ran for $($TotalTime.TotalSeconds) seconds" | |
| } | |
| } | |
| try { | |
| Set-TaskbarLocation -Location 'left' -RestartExplorer -Confirm:$false | |
| Write-Output 'SUCCESS: Successfully set taskbar location' | |
| } catch { | |
| Write-Output "ERROR: Failed to move taskbar. $($_.exception.message)" | |
| exit 1 | |
| } | |
| } | |
| $currentUser = Get-CimInstance -ClassName Win32_ComputerSystem -ErrorAction silentlycontinue | Select-Object -ExpandProperty UserName | |
| if ($null -eq $currentUser) { | |
| Write-Output 'WARNING: No user currently logged in' | |
| exit 0 | |
| } else { | |
| Invoke-AsCurrentUser -ScriptBlock $scriptblock -CaptureOutput -UseWindowsPowerShell -Visible -CacheToDisk | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment