Created
March 11, 2023 12:38
-
-
Save obsti8383/80e2a44ab8fa74a9e03149caf342cd09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## deletes all link files on Desktop and Common Desktop Directories, that link to Program Files. | |
## | |
# Get the desktop folder path | |
$desktopPath = [Environment]::GetFolderPath("Desktop") | |
$desktopPathPublic = [Environment]::GetFolderPath("CommonDesktopDirectory") | |
$ErrorActionPreference = "Stop" | |
# Get a list of all the shortcut files in the desktop folder | |
$shortcutFiles = Get-ChildItem $desktopPath -Filter *.lnk | |
$shortcutFiles += Get-ChildItem $desktopPathPublic -Filter *.lnk | |
$Shell = New-Object -ComObject WScript.Shell | |
# Loop through each shortcut file and check if it targets an installed program | |
foreach ($shortcutFile in $shortcutFiles) { | |
Write-Host "Checking $shortcutFile" | |
$target = $Shell.CreateShortcut($shortcutFile.FullName).TargetPath | |
#$target | |
if ($target -match "^([A-Z]:\\)?(Program Files|Program Files \(x86\))\\") { | |
Write-Host "Removing $shortcutFile" | |
Remove-Item $shortcutFile.FullName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment