Skip to content

Instantly share code, notes, and snippets.

@pinecones-sx
Last active April 20, 2017 16:38
Show Gist options
  • Save pinecones-sx/86254ee2e0832ae709f0cdbee279eb5a to your computer and use it in GitHub Desktop.
Save pinecones-sx/86254ee2e0832ae709f0cdbee279eb5a to your computer and use it in GitHub Desktop.
removes some registry points for SysAid
# Remove registry entries
$null = New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
# Remove registry entries
$oldRegKeys = `
'HKLM:\SOFTWARE\Ilient',
'HKLM:\SOFTWARE\Wow6432Node\Ilient',
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FC5E1D1D-6D3F-4844-A937-567D589F655E}'
$installedKeys = `
'HKCR:\Installer',
'HKLM:\SOFTWARE\Classes\Installer',
'HKLM:\SOFTWARE\WOW6432Node\Classes\Installer'
$subKeys = 'Products','Features','UpgradeCodes'
$targetKeys = @()
ForEach ($subKey in $subKeys){
ForEach ($installedKey in $installedKeys){
$targetKeys += ($installedKey + '\' + $subKey)
}
}
# Keep only keys that exist
$targetKeys = $targetKeys | Where {(Test-Path $_)}
# Find any registry keys with properties matching the $findFilter ('SysAid')
$matchingKeys = (
$targetKeys |
Get-ChildItem -ErrorAction SilentlyContinue |
Get-ItemProperty |
ForEach {If (Find-PropText $_ $findFilter){$_}}
)
# Find any package codes listed, we will use these to discover more potential registry points
$packageCodes = $matchingKeys | Select -ExpandProperty PackageCode | Sort -Unique
# Search target keys for sub-properties matching any discoveries from $packageCodes
ForEach ($iCode in $packageCodes){
$codeResults = (
$targetKeys |
Get-ChildItem -ErrorAction SilentlyContinue |
Get-ItemProperty |
ForEach {If (Find-PropText $_ ('*' + $iCode + '*')){$_}}
)
# If any results, add each individually to the matching keys.
If ($codeResults){$codeResults | %{$matchingKeys += $_}}
}
# If any old keys exist, add them to the results
ForEach ($oldKey in $oldRegKeys){
If ((Test-Path $oldKey)){$matchingKeys += (Get-ItemProperty $oldKey)}
}
# Clear any duplicate key matches from list, then delete all matches
$matchingKeys = $matchingKeys | Sort -Unique PSPath
ForEach ($iMatch in ($matchingKeys.PSPath)){
Remove-Item $iMatch -Force -Recurse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment