Remote uninstall with GUI v2


posted by Felipe
09-21-2010

Downloads: 920
File size: 3.8kB
Views: 2,961

Embed
Remote uninstall with GUI v2
  1. ################################################################## 
  2. ####                                                           
  3. ####                 REMOTE UNINSTALL           
  4. ####                                                           
  5. ####             Written by Felipe Binotto     
  6. ####               Date: 01/05/10        
  7. ####                            
  8. #### 
  9. ################################################################## 
  10. function listprograms { 
  11.  
  12. Get-WmiObject win32_product -ComputerName $address.Text | Out-GridView 
  13.  
  14.  
  15. function remoteuninstall { 
  16.  
  17. $app = Get-WmiObject win32_product -ComputerName $address.Text | Where-Object {$_.name -match $program.Text
  18. $returnvalue = $app.uninstall() | Select-Object -Property returnvalue 
  19. if($returnvalue.returnvalue -eq "0"
  20. {[Windows.Forms.MessageBox]::Show("Installation was successful!")} 
  21. else{[Windows.Forms.MessageBox]::Show("Installation was not successful!")} 
  22.  
  23.  
  24. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms"
  25. [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing"
  26.  
  27. $Form = New-Object System.Windows.Forms.Form 
  28.  
  29. $Form.width = 500 
  30. $Form.height = 350 
  31. $Form.Text = "Remote Uninstall" 
  32. $Form.backcolor = "#5D8AA8" 
  33. $Form.maximumsize = New-Object System.Drawing.Size(500, 350) 
  34. $Form.startposition = "centerscreen" 
  35. $Form.KeyPreview = $True 
  36. $Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")  
  37.     {$Form.Close()}}) 
  38.  
  39. $ListButton = new-object System.Windows.Forms.Button 
  40. $ListButton.Location = new-object System.Drawing.Size(50,200) 
  41. $ListButton.Size = new-object System.Drawing.Size(130,30) 
  42. $ListButton.Text = "List Programs" 
  43. $ListButton.FlatAppearance.MouseOverBackColor = [System.Drawing.Color]::FromArgb(255, 255, 192); 
  44. $ListButton.ImageAlign = [System.Drawing.ContentAlignment]::MiddleLeft
  45. $Listbutton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat 
  46. $ListButton.Add_Click({listprograms}) 
  47.  
  48. $Form.Controls.Add($ListButton
  49.  
  50. $address = new-object System.Windows.Forms.TextBox 
  51. $address.Location = new-object System.Drawing.Size(65,60) 
  52. $address.Size = new-object System.Drawing.Size(100,20) 
  53.  
  54. $Form.Controls.Add($address
  55.  
  56. $addresslabel = new-object System.Windows.Forms.Label 
  57. $addresslabel.Location = new-object System.Drawing.Size(70,10) 
  58. $addresslabel.size = new-object System.Drawing.Size(100,50) 
  59. $addresslabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold
  60. $addresslabel.Text = "Computer" 
  61. $Form.Controls.Add($addresslabel
  62.  
  63. $programlabel = new-object System.Windows.Forms.Label 
  64. $programlabel.Location = new-object System.Drawing.Size(270,10) 
  65. $programlabel.size = new-object System.Drawing.Size(200,50) 
  66. $programlabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold
  67. $programlabel.Text = "Program to Uninstall" 
  68. $Form.Controls.Add($programlabel
  69.  
  70. $program = new-object System.Windows.Forms.TextBox 
  71. $program.Location = new-object System.Drawing.Size(300,60) 
  72. $program.Size = new-object System.Drawing.Size(100,20) 
  73.  
  74.  
  75. $Form.Controls.Add($program
  76.  
  77. $UninstallButton = new-object System.Windows.Forms.Button 
  78. $UninstallButton.Location = new-object System.Drawing.Size(290,200) 
  79. $UninstallButton.Size = new-object System.Drawing.Size(130,30) 
  80. $UninstallButton.FlatAppearance.MouseOverBackColor = [System.Drawing.Color]::FromArgb(255, 255, 192); 
  81. $UninstallButton.ImageAlign = [System.Drawing.ContentAlignment]::MiddleLeft
  82. $UninstallButton.Text = "Uninstall" 
  83. $Uninstallbutton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat 
  84. $UninstallButton.Add_Click({remoteuninstall}) 
  85.  
  86. $viclabel = new-object System.Windows.Forms.Label 
  87. $viclabel.Location = new-object System.Drawing.Size(140,250) 
  88. $viclabel.size = new-object System.Drawing.Size(200,50) 
  89. $Form.Controls.Add($viclabel
  90.  
  91. $Form.Controls.Add($UninstallButton
  92.  
  93. $Form.Add_Shown({$Form.Activate()}) 
  94. $Form.ShowDialog() 

Easiest way to perform remote installations.

That's the version 2. Some bugs fixed.

There's a function to list the programs installed.

To uninstall a program just type the computer name and the program name.

Be careful not to be too generic. If you just type Adobe, it will uninstall all adobe programs installed in the computer.

Comments

lostinfuture wrote re: Remote uninstall with GUI v2
on 11-18-2010 8:13 AM

how to run it?

Felipe wrote re: Remote uninstall with GUI v2
on 11-21-2010 2:58 AM

.\remoteuninstall.ps1

weston_111 wrote re: Remote uninstall with GUI v2
on 04-26-2012 10:16 AM

I have compiled an updated version of this. Using your form with some scripting from another site. Check it out and let me know what you think. here is the link:

powershell.com/.../uninstall.ps1.aspx

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.