Files
windows-scripts/ChangeShortcutPath.ps1
2023-12-05 19:39:38 -06:00

34 lines
973 B
PowerShell
Executable File

$oldPrefix = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
$newPrefix = "C:\Program Files\Google\Chrome\Application\chrome.exe"
$searchPath = "D:\OneDrive\Twitch"
$dryRun = $FALSE
$shell = new-object -com wscript.shell
if ( $dryRun ) {
write-host "Executing dry run" -foregroundcolor green -backgroundcolor black
} else {
write-host "Executing real run" -foregroundcolor red -backgroundcolor black
}
dir $searchPath -filter *.lnk -recurse | foreach {
$lnk = $shell.createShortcut( $_.fullname )
$oldPath= $lnk.targetPath
$lnkRegex = "^" + [regex]::escape( $oldPrefix )
if ( $oldPath -match $lnkRegex ) {
$newPath = $oldPath -replace $lnkRegex, $newPrefix
write-host "Found: " + $_.fullname -foregroundcolor yellow -backgroundcolor black
write-host " Replace: " + $oldPath
write-host " With: " + $newPath
if ( !$dryRun ) {
$lnk.targetPath = $newPath
$lnk.Save()
}
}
}