Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()]
- param (
- [Parameter(Mandatory)][string]$computername
- )
- $InstalledList = @()
- #Define the variable to hold the location of Currently Installed Programs
- $UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
- $UninstallKey64="SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
- #Create an instance of the Registry Object and open the HKLM base key
- $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername)
- #Drill down into the Uninstall key using the OpenSubKey Method
- $regkey=$reg.OpenSubKey($UninstallKey)
- $regkey64=$reg.OpenSubKey($UninstallKey64)
- #Retrieve an array of string that contain all the subkey names
- $subkeys=$regkey.GetSubKeyNames()
- $subkeys64=$regkey64.GetSubKeyNames()
- # Add a number selector to each line.
- $appNumber = 1
- #Open each Subkey and use GetValue Method to return the required values for each
- foreach($key in $subkeys){
- $thisKey=$UninstallKey+"\\"+$key
- $thisSubKey=$reg.OpenSubKey($thisKey)
- $obj = New-Object PSObject
- $obj | Add-Member -MemberType NoteProperty -Name "AppNumber" -Value $appNumber; $appNumber++;
- $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
- $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
- $obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
- $obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
- $obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
- $obj | Add-Member -MemberType NoteProperty -Name "UninstallString" -Value $($thisSubKey.GetValue("UninstallString"))
- $InstalledList += $obj
- }
- foreach($key in $subkeys64){
- $thisKey=$UninstallKey64+"\\"+$key
- $thisSubKey=$reg.OpenSubKey($thisKey)
- $obj = New-Object PSObject
- $obj | Add-Member -MemberType NoteProperty -Name "AppNumber" -Value $appNumber; $appNumber++;
- $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
- $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
- $obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
- $obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
- $obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
- $obj | Add-Member -MemberType NoteProperty -Name "UninstallString" -Value $($thisSubKey.GetValue("UninstallString"))
- $InstalledList += $obj
- }
- $apps = $InstalledList | Where-Object { $_.DisplayName -and $_.UninstallString -like "MsiExec*" } | select AppNumber, ComputerName, DisplayName, DisplayVersion, Publisher, UninstallString
- $apps | Format-Table -AutoSize
- $uninstallApp = Read-Host -Prompt "Select an App to uninstall" -Verbose
- $UninstallStr = ($apps | Where-Object {$_.appNumber -like $uninstallApp}).uninstallString
- Invoke-Command -ComputerName $computerName -ScriptBlock {
- $UninstallStr = $args[0]
- $FullUninstallStr = $UninstallStr + ' /QN /L*V "C:\Temp\RemoteUninstall.log" REBOOT=R'
- ## Execute the software installer
- Start-Process -FilePath "msiexec.exe" -ArgumentList $FullUninstallStr -Wait -Passthru
- } -ArgumentList $UninstallStr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement