Skip to content

Instantly share code, notes, and snippets.

@themaximax
Last active November 27, 2025 09:55
Show Gist options
  • Select an option

  • Save themaximax/bffc0fa4403d61c7889157dd6e9f037b to your computer and use it in GitHub Desktop.

Select an option

Save themaximax/bffc0fa4403d61c7889157dd6e9f037b to your computer and use it in GitHub Desktop.
$old = "\\terminal-pf\"
$new = "\\agrohold.ru\pf\"
$paths = @(
"C:\Users\*\Desktop",
"C:\Users\*\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar",
"C:\Users\*\AppData\Roaming\Microsoft\Windows\Start Menu",
"C:\ProgramData\Microsoft\Windows\Start Menu"
)
$updatedCount = 0
$shell = New-Object -ComObject WScript.Shell
foreach ($path in $paths) {
Get-ChildItem -Path $path -Filter *.lnk -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
$shortcut = $shell.CreateShortcut($_.FullName)
if ($shortcut.TargetPath -like "*$old*") {
$shortcut.TargetPath = $shortcut.TargetPath -replace [regex]::Escape($old), $new
$shortcut.WorkingDirectory = $shortcut.WorkingDirectory -replace [regex]::Escape($old), $new
$shortcut.Save()
$updatedCount++
Write-Host "Updated: $($_.FullName)"
}
}
}
Write-Host "==============================="
Write-Host "Total shortcuts updated: $updatedCount"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment