Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- [Parameter(Mandatory=$true)]
- [String]$Computername
- )
- $UninstallKeys = @(
- "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
- "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
- )
- $appNumber = 0
- function InstalledList {
- foreach($UninstallKey in $UninstallKeys) {
- #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)
- #Retrieve an array of string that contain all the subkey names
- $Subkeys = $Regkey.GetSubKeyNames()
- foreach($key in $subkeys) {
- $thisKey=$UninstallKey+"\\"+$key
- $thisSubKey=$reg.OpenSubKey($thisKey)
- [PSCustomObject] @{
- #AppNumber = $appNumber++
- ComputerName = $Computername
- DisplayName = $thisSubKey.GetValue("DisplayName")
- DisplayVersion = $thisSubKey.GetValue("DisplayVersion")
- InstallLocation = $thisSubKey.GetValue("InstallLocation")
- Publisher = $thisSubKey.GetValue("Publisher")
- UninstallString = $thisSubKey.GetValue("UninstallString")
- }
- }
- }
- }
- $Apps = InstalledList | Where-Object { $_.DisplayName -and $_.UninstallString -like "MsiExec*" } | Sort-Object DisplayName | Select-Object @{Name="AppNumber";Expression={$global:appnumber; $global:appnumber++};}, DisplayName, Publisher, DisplayVersion, ComputerName, UninstallString
- $Apps | Format-Table -AutoSize
- $uninstallApp = Read-Host -Prompt "Select an App to uninstall" -Verbose
- $uninstallProg = $apps | Where-Object {$_.appNumber -eq $uninstallApp}
- $UninstallStr = ($uninstallProg).uninstallString -replace "/I", "/X"
- Write-Verbose -Message "Uninstalling $(($uninstallProg).DisplayName) on $(($uninstallProg).ComputerName)..." -Verbose
- Invoke-Command -ComputerName $Computername -ScriptBlock {
- $UninstallStr = $args[0]
- $softwareName = $args[1]
- $logFile = "C:\temp\$($softwarename -replace '\s', '')_uninstall.log"
- $arguments = (($UninstallStr -replace "MsiExec.exe ", "") -replace "msiexec", "") + " /QN /L*V $logFile REBOOT=R"
- #Execute the software installer
- Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -Passthru
- } -ArgumentList $UninstallStr, ($uninstallProg).DisplayName
- Pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement