|
$BasePath = $PSScriptRoot |
|
|
|
# Removes the Search icon from Taskbar |
|
Function Remove-Search { |
|
# Define the registry path and property name |
|
$RegistryPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search' |
|
$PropertyName = 'SearchboxTaskbarMode' |
|
$currentValue = (Get-ItemProperty -Path $RegistryPath -Name $PropertyName).$PropertyName |
|
$NewValue = '0' |
|
If ($currentValue -eq 1) { |
|
Write-Output "Updating SearchboxTaskbarMode" |
|
Set-ItemProperty -Path $RegistryPath -Name $PropertyName -Value $NewValue |
|
} |
|
} |
|
|
|
# If your PC is managed by an organization (at work) then they might use this file to define default pinned items |
|
Function Remove-Defaults { |
|
$replacementText = '<!-- Removed CustomTaskbarLayoutCollection -->' |
|
$filename = "$env:LOCALAPPDATA\Microsoft\Windows\Shell\LayoutModification.xml" |
|
|
|
if (!(Select-String -Path $filename -Pattern $replacementText -Quiet)) { |
|
Write-Output "Updating LayoutModification.xml" |
|
$regex = '(?ms)(\n^\s*<CustomTaskbarLayoutCollection\s*?).*(CustomTaskbarLayoutCollection>)' |
|
|
|
# Remove the CustomTaskbarLayoutCollection entry |
|
(Get-Content -raw $filename) -replace $regex, $replacementText | Set-Content $filename |
|
} |
|
} |
|
|
|
# Windows Taskbar pinned icons are stored in registry key and directory with shortcuts. |
|
# |
|
# Important: You need to maintain both of these in order for the shortcuts to work. |
|
Function Backup-Taskbar { |
|
$BackupDir = "$BasePath\Backup" |
|
$RegistryFile = "$BackupDir\taskbar-favourites.reg" |
|
$ShortCutDir = "$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" |
|
# Create Backup Directory |
|
if (-not (Test-Path -Path $BackupDir)) { |
|
Write-Output "Creating $BackupDir" |
|
New-Item -ItemType Directory -Force -Path $BackupDir | Out-Null |
|
} |
|
|
|
If (!(Test-Path $RegistryFile -PathType Leaf)) { |
|
Write-Output "Creating Taskbar backup" |
|
Invoke-Command { reg export 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband' $RegistryFile /y } |
|
If (Test-Path $BackupDir\TaskBar) { Remove-Item -Recurse $BackupDir\TaskBar } |
|
New-Item -ItemType Directory -Force -Path $BackupDir\TaskBar | Out-Null |
|
Copy-item -Force -Recurse $ShortCutDir\*.lnk -Destination $BackupDir\TaskBar |
|
} |
|
|
|
# Checking if registry keys are different in the .reg file seems to be more complicated so I didn't bother |
|
Invoke-Command { reg import $RegistryFile } |
|
Copy-item -Force -Recurse $BackupDir\TaskBar\* -Destination $ShortCutDir |
|
} |
|
|
|
# Refresh the Taskbar if icons have changed |
|
# |
|
# This function need to be executed only if Backup-Taskbar is used |
|
Function Restart-Explorer { |
|
get-process explorer | Stop-Process -Force |
|
} |
|
|
|
# These can be just done once on init (they don't change in my case) |
|
Backup-Taskbar |
|
Restart-Explorer |
|
|
|
# Run it in background periodically (if cannot use Windows Services) |
|
# At my workplace they revert these every 100 minutes... |
|
while ($true) { |
|
Remove-Search |
|
Remove-Defaults |
|
|
|
Start-Sleep -Seconds 60 |
|
} |