Untitled
unknown
plain_text
5 months ago
1.5 kB
4
Indexable
# Define the software name pattern to search for (matches "Lightshot" with any version suffix) $softwareNamePattern = "Lightshot" # Define the registry paths where installed software information is usually stored $uninstallKeys = @( "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall" ) # Loop through each registry path to find matching software foreach ($keyPath in $uninstallKeys) { $uninstallEntries = Get-ChildItem -Path $keyPath | ForEach-Object { # Try to get the DisplayName property for each subkey $displayName = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).DisplayName if ($displayName -like "$softwareNamePattern*") { # If a match is found, return the full uninstall command [PSCustomObject]@{ Name = $displayName UninstallString = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).UninstallString } } } # If any matches were found, proceed to uninstall them foreach ($entry in $uninstallEntries) { if ($entry) { Write-Host "Uninstalling: $($entry.Name)" # Run the uninstall command Start-Process -FilePath $entry.UninstallString -ArgumentList "/S" -NoNewWindow -Wait Write-Host "Successfully uninstalled: $($entry.Name)" } } }
Editor is loading...
Leave a Comment