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 +} 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 }