From 9aad86c7c3ef6bb81a08fd694433354c006775fe Mon Sep 17 00:00:00 2001 From: Xtraim <48596203+Xtraim@users.noreply.github.com> Date: Fri, 7 Aug 2026 13:26:12 +0200 Subject: [PATCH 1/2] Refactor taskbar detection script for Windows 11 Updated version to 1.1 and improved registry check logic for Windows 11 taskbar alignment. Before you had a function to check if value exist, then read the value, then compare. Check registry -> read registry -> compare Now you read the value, and if not readable = fail, else compare. read registry if exist -> compare More simple and visible, less registry access. --- .../Move-Windows11Taskbar-Detection.ps1 | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/Move-Windows11Taskbar/Move-Windows11Taskbar-Detection.ps1 b/Move-Windows11Taskbar/Move-Windows11Taskbar-Detection.ps1 index dc8e818..cd4242c 100644 --- a/Move-Windows11Taskbar/Move-Windows11Taskbar-Detection.ps1 +++ b/Move-Windows11Taskbar/Move-Windows11Taskbar-Detection.ps1 @@ -6,39 +6,30 @@ Exits with code 0 if aligned left, code 1 otherwise. .NOTES Author: Jannik Reinhard (jannikreinhard.com) - Version: 1.0 + Version: 1.1 #> -function Test-RegistryValue { - param ( - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()]$Path, +$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" +$Value = "TaskbarAl" - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()]$Value - ) - - try { - Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null - return $true - } catch { - return $false - } -} - -$path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -$value = "TaskbarAl" - -$osCaption = (Get-CimInstance -ClassName Win32_OperatingSystem -Property Caption).Caption -if ($osCaption -notlike "*Windows 11*") { - Write-Host "Not Windows 11, skipping" +# Windows 11 only +if (Get-ComputerInfo.OsBuildNumber -lt 22000) { + Write-Output "Not Windows 11 - compliant" exit 0 } -if (Test-RegistryValue -Path $path -Value $value) { - if ((Get-ItemProperty -Path $path -Name $value).TaskbarAl -eq "0") { +try { + $CurrentValue = (Get-ItemProperty -Path $Path -Name $Value -ErrorAction Stop).TaskbarAl + + if ($CurrentValue -eq 0) { + Write-Output "Compliant - Taskbar aligned left" exit 0 } -} -exit 1 + Write-Output "Non-compliant - TaskbarAl=$CurrentValue" + exit 1 +} +catch { + Write-Output "Non-compliant - TaskbarAl not found" + exit 1 +} From ab2d0547e4fa47d581c6eab0fcda52c16c5b6936 Mon Sep 17 00:00:00 2001 From: Xtraim <48596203+Xtraim@users.noreply.github.com> Date: Fri, 7 Aug 2026 13:33:07 +0200 Subject: [PATCH 2/2] Refactor taskbar alignment script for Windows 11 Updated version to 1.1 and improved OS check for Windows 11. New-itemproerty instead of set : Because if value exist (update, if value not existing (create), in all case TaskbarAl = 0. Delete test path, because try and catch already manage errors. --- .../Move-Windows11Taskbar-Remediation.ps1 | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/Move-Windows11Taskbar/Move-Windows11Taskbar-Remediation.ps1 b/Move-Windows11Taskbar/Move-Windows11Taskbar-Remediation.ps1 index 6536fea..472b0e7 100644 --- a/Move-Windows11Taskbar/Move-Windows11Taskbar-Remediation.ps1 +++ b/Move-Windows11Taskbar/Move-Windows11Taskbar-Remediation.ps1 @@ -4,46 +4,37 @@ .DESCRIPTION Sets the TaskbarAl registry value to 0, aligning the Windows 11 taskbar to the left. Includes an OS check to ensure it only runs on Windows 11. + Intune settings : + Run this script using the logged-on credentials : Yes + Run script in 64-bit PowerShell : Yes + Enforce script signature check : No .NOTES Author: Jannik Reinhard (jannikreinhard.com) - Version: 1.0 + Version: 1.1 #> -function Test-RegistryValue { - param ( - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()]$Path, +$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" +$Value = "TaskbarAl" - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()]$Value - ) - - try { - Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null - return $true - } catch { - return $false - } +# Windows 11 only +if ((Get-ComputerInfo).OsBuildNumber -lt 22000) { + Write-Output "Not Windows 11 - skipping" + exit 0 } -$path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -$value = "TaskbarAl" +try { -$osCaption = (Get-CimInstance -ClassName Win32_OperatingSystem -Property Caption).Caption -if ($osCaption -notlike "*Windows 11*") { - Write-Host "Not Windows 11, skipping" + New-ItemProperty ` + -Path $Path ` + -Name $Value ` + -PropertyType DWord ` + -Value 0 ` + -Force | Out-Null + + Write-Output "Taskbar alignment set to left (TaskbarAl=0)" exit 0 } - -if (Test-Path $path) { - try { - Set-ItemProperty -Path $path -Name $value -Value 0 -Force - exit 0 - } catch { - Write-Error "Failed to set taskbar alignment: $_" - exit 1 - } -} else { - Write-Error "Registry path not found: $path" +catch { + Write-Output "Failed to set TaskbarAl : $($_.Exception.Message)" exit 1 }