Created
January 9, 2019 18:45
-
-
Save ArtisanByteCrafter/25fbbdc7d41db1445488372e0efe279d 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
# put programs to remove in this array. Java and Opera are in this example. | |
$remove = @('*Java*', '*Opera*' ) | |
function Get-InstalledApps { | |
param ( | |
[Parameter(ValueFromPipeline=$true)] | |
[string[]]$ComputerName = $env:COMPUTERNAME, | |
[string]$NameRegex = '' | |
) | |
foreach ($comp in $ComputerName) { | |
$keys = '','\Wow6432Node' | |
foreach ($key in $keys) { | |
try { | |
$apps = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$comp).OpenSubKey("SOFTWARE$key\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames() | |
} catch { | |
continue | |
} | |
foreach ($app in $apps) { | |
$program = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$comp).OpenSubKey("SOFTWARE$key\Microsoft\Windows\CurrentVersion\Uninstall\$app") | |
$name = $program.GetValue('DisplayName') | |
if ($name -and $name -match $NameRegex) { | |
[pscustomobject]@{ | |
ComputerName = $comp | |
DisplayName = $name | |
DisplayVersion = $program.GetValue('DisplayVersion') | |
Publisher = $program.GetValue('Publisher') | |
InstallDate = $program.GetValue('InstallDate') | |
UninstallString = $program.GetValue('UninstallString') | |
Bits = $(if ($key -eq '\Wow6432Node') {'64'} else {'32'}) | |
Path = $program.name | |
} | |
} | |
} | |
} | |
} | |
} | |
$array = Foreach ($r in $remove){ | |
Get-InstalledApps | Where-Object {$_.DisplayName -like $r } | Select-Object -ExpandProperty UninstallString | |
} | |
ForEach ($a in $array) { | |
& "$env:ComSpec" /c $a /quiet | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment