Misc Slideshow

  1. ########################################################################################## 
  2. ############################### Uninstaller Version 1.0 ################################## 
  3. ########################################################################################## 
  4. ## Built this script using multiple resources. I pulled some of the Functions and forms ## 
  5. ## from the internet. I pieced them together into an all-in-one Uninstaller. Enjoy :)   ##                                         ## 
  6. ########################################################################################## 
  7. ## Credits:                                                                             ## 
  8. ## Felipe Binotto @:                                                                    ## 
  9. ## http://powershell.com/cs/media/p/7673.aspx                                           ## 
  10. ## Sitaram @:                                                                           ## 
  11. ## http://techibee.com/powershell/powershell-uninstall-software-on-remote-computer/1400 ## 
  12. ########################################################################################## 
  13.  
  14.  
  15. ################################################ 
  16. ### Beginning of List Programs Function ######## 
  17. ################################################ 
  18.  
  19. Function ListPrograms { 
  20.  
  21. [cmdletbinding()]             
  22.  
  23. [cmdletbinding()] 
  24. param
  25. [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] 
  26. [string[]]$ComputerName = $env:computername             
  27.  
  28. )             
  29.  
  30. begin { 
  31. $UninstallRegKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" 
  32. }             
  33.  
  34. process { 
  35. foreach($Computer in $ComputerName) { 
  36.   Write-Verbose "Working on $Computer" 
  37.   if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) { 
  38.    $HKLM   = [microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computer
  39.    $UninstallRef  = $HKLM.OpenSubKey($UninstallRegKey
  40.    $Applications = $UninstallRef.GetSubKeyNames()             
  41.  
  42.    foreach ($App in $Applications) { 
  43.     $AppRegistryKey  = $UninstallRegKey + "\\" + $App 
  44.     $AppDetails   = $HKLM.OpenSubKey($AppRegistryKey
  45.     $AppGUID   = $App 
  46.     $AppDisplayName  = $($AppDetails.GetValue("DisplayName")) 
  47.     $AppVersion   = $($AppDetails.GetValue("DisplayVersion")) 
  48.     $AppPublisher  = $($AppDetails.GetValue("Publisher")) 
  49.     $AppInstalledDate = $($AppDetails.GetValue("InstallDate")) 
  50.     $AppUninstall  = $($AppDetails.GetValue("UninstallString")) 
  51.     if(!$AppDisplayName) { continue
  52.     $OutputObj = New-Object -TypeName PSobject 
  53.     $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper() 
  54.     $OutputObj | Add-Member -MemberType NoteProperty -Name AppName -Value $AppDisplayName 
  55.     $OutputObj | Add-Member -MemberType NoteProperty -Name AppVersion -Value $AppVersion 
  56.     $OutputObj | Add-Member -MemberType NoteProperty -Name AppVendor -Value $AppPublisher 
  57.     $OutputObj | Add-Member -MemberType NoteProperty -Name InstalledDate -Value $AppInstalledDate 
  58.     $OutputObj | Add-Member -MemberType NoteProperty -Name UninstallKey -Value $AppUninstall 
  59.     $OutputObj | Add-Member -MemberType NoteProperty -Name AppGUID -Value $AppGUID 
  60.     $OutputObj# | Select ComputerName, DriveName 
  61.    
  62.   
  63. }             
  64.  
  65. end {} 
  66.  
  67. ################################################ 
  68. ### End of the List Programs Function ########## 
  69. ################################################ 
  70.  
  71. ################################################ 
  72. ### Beginning of Uninstall Programs Function ### 
  73. ################################################ 
  74.  
  75. Function UninstallProgram { 
  76.  
  77. [cmdletbinding()]             
  78.  
  79. param (             
  80.  
  81. [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] 
  82. [string]$ComputerName = $env:computername
  83. [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory=$true)] 
  84. [string]$AppGUID 
  85. )             
  86.  
  87. try { 
  88.   $returnval = ([WMICLASS]"\\$computerName\ROOT\CIMV2:win32_process").Create("msiexec `/x$AppGUID `/qn"
  89. } catch { 
  90.   write-error "Failed to trigger the uninstallation. Review the error message" 
  91.   $_ 
  92.   exit 
  93. switch ($($returnval.returnvalue)){ 
  94.   0 { "Uninstallation command triggered successfully"
  95.   2 { "You don't have sufficient permissions to trigger the command on $Computer"
  96.   3 { "You don't have sufficient permissions to trigger the command on $Computer"
  97.   8 { "An unknown error has occurred"
  98.   9 { "Path Not Found"
  99.   9 { "Invalid Parameter"
  100.  
  101. ################################################ 
  102. ### End of Uninstall Programs Function ######### 
  103. ################################################ 
  104.  
  105. ################################################ 
  106. ### Start of ForEach Functions ################# 
  107. ################################################ 
  108.  
  109. Function FElist { 
  110. $ServerList = Get-Content $Address.text 
  111. $ProgramName = $program.Text 
  112. $OutputListArray= @() 
  113. foreach($Server in $ServerList){ 
  114. $ListResults= ListPrograms -ComputerName $Server | Where-Object {$_.AppName -like "*$ProgramName*"} | Select-Object
  115. ComputerName, AppName, AppVersion | Format-Table -AutoSize 
  116. $OutputListArray += $ListResults 
  117. $OutputListArray | out-file $env:userprofile\documents\temp_programs.txt 
  118. $ListFile= "$env:userprofile\documents\temp_programs.txt" 
  119. Invoke-Item $ListFile 
  120.  
  121. Function FEuninstall { 
  122. $ServerList = Get-Content $Address.text 
  123. $ProgramName = $program.Text 
  124. $OutputProgArray= @() 
  125. foreach($Server in $ServerList){ 
  126. $UninstResult= ListPrograms -ComputerName $Server | Where-Object {$_.AppName -like "*$ProgramName*"} | ` 
  127. UninstallProgram 
  128. $OutputProgArray += "$Server $ProgramName " + $UninstResult  
  129. $OutputProgArray | out-file $env:userprofile\documents\temp_uninst.txt 
  130. $Progfile= "$env:userprofile\documents\temp_uninst.txt" 
  131. Invoke-Item $Progfile 
  132. ################################################ 
  133. ### End of ForEach Functions $################## 
  134. ################################################ 
  135.  
  136. ############################################################## 
  137. ### Beginning of Windows Forms Worker ######################## 
  138. ############################################################## 
  139.  
  140.     [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  
  141.     [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")  
  142.       
  143.     $Form = New-Object System.Windows.Forms.Form  
  144.       
  145.     $Form.width = 500 
  146.     $Form.height = 300 
  147.     $Form.Text = "Remote Uninstall  -By Weston Uptagrafft"  
  148.     $Form.backcolor = "#5D8AA8"  
  149.     $Form.maximumsize = New-Object System.Drawing.Size(500, 300)  
  150.     $Form.startposition = "centerscreen"  
  151.     $Form.KeyPreview = $True  
  152.     $Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")   
  153.         {$Form.Close()}})  
  154.  
  155.     $Infolabel = new-object System.Windows.Forms.Label  
  156.     $Infolabel.Location = new-object System.Drawing.Size(20,10)  
  157.     $Infolabel.size = new-object System.Drawing.Size(450,80)  
  158.     $Infolabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",10,[System.Drawing.FontStyle]::Bold)  
  159.     $Infolabel.Text = "!! INFORMATION : Make sure you List Programs first. Don't be to vague when specifying the" + 
  160.     " Program. For instance if you type Adobe it will unintall all adobe products. Try Adobe Reader and List" + 
  161.     " Programs to see what you get. Once you get the correct output when listing then you can uninstall. Uses" +  
  162.     " MSIexec with /qn switch."  
  163.     $Form.Controls.Add($Infolabel)  
  164.       
  165.     $ListButton = new-object System.Windows.Forms.Button  
  166.     $ListButton.Location = new-object System.Drawing.Size(50, 200)  
  167.     $ListButton.Size = new-object System.Drawing.Size(130,30)  
  168.     $ListButton.Text = "List Programs"  
  169.     $ListButton.FlatAppearance.MouseOverBackColor = [System.Drawing.Color]::FromArgb(255, 255, 192);  
  170.     $ListButton.ImageAlign = [System.Drawing.ContentAlignment]::MiddleLeft;  
  171.     $Listbutton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat  
  172.     $ListButton.Add_Click({FElist})  
  173.       
  174.     $Form.Controls.Add($ListButton)  
  175.       
  176.     $address = new-object System.Windows.Forms.TextBox  
  177.     $address.Location = new-object System.Drawing.Size(45,160)  
  178.     $address.Size = new-object System.Drawing.Size(220,20)  
  179.       
  180.     $Form.Controls.Add($address)  
  181.       
  182.     $addresslabel = new-object System.Windows.Forms.Label  
  183.     $addresslabel.Location = new-object System.Drawing.Size(45,110)  
  184.     $addresslabel.size = new-object System.Drawing.Size(170,50)  
  185.     $addresslabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold)  
  186.     $addresslabel.Text = "Path to list of Computers:"  
  187.     $Form.Controls.Add($addresslabel)  
  188.       
  189.     $programlabel = new-object System.Windows.Forms.Label  
  190.     $programlabel.Location = new-object System.Drawing.Size(285,110)  
  191.     $programlabel.size = new-object System.Drawing.Size(140,50)  
  192.     $programlabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold)  
  193.     $programlabel.Text = "Program to Uninstall:"  
  194.     $Form.Controls.Add($programlabel)  
  195.       
  196.     $program = new-object System.Windows.Forms.TextBox  
  197.     $program.Location = new-object System.Drawing.Size(285,160)  
  198.     $program.Size = new-object System.Drawing.Size(160,20)  
  199.      
  200.     $Form.Controls.Add($program)  
  201.  
  202.     $UninstallButton = new-object System.Windows.Forms.Button  
  203.     $UninstallButton.Location = new-object System.Drawing.Size(300,200)  
  204.     $UninstallButton.Size = new-object System.Drawing.Size(130,30)  
  205.     $UninstallButton.FlatAppearance.MouseOverBackColor = [System.Drawing.Color]::FromArgb(255, 255, 192);  
  206.     $UninstallButton.ImageAlign = [System.Drawing.ContentAlignment]::MiddleLeft;  
  207.     $UninstallButton.Text = "Uninstall"  
  208.     $Uninstallbutton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat  
  209.     $UninstallButton.Add_Click({FEuninstall})  
  210.  
  211.       
  212.     $viclabel = new-object System.Windows.Forms.Label  
  213.     $viclabel.Location = new-object System.Drawing.Size(140,250)  
  214.     $viclabel.size = new-object System.Drawing.Size(200,50)  
  215.     $Form.Controls.Add($viclabel)  
  216.       
  217.     $Form.Controls.Add($UninstallButton)  
  218.       
  219.     $Form.Add_Shown({$Form.Activate()})  
  220.     $Form.ShowDialog()  
  221.  
  222.  
  223. ############################################################## 
  224. ### End of Windows Forms Worker ############################## 
  225. ############################################################## 
 
Loading...
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.