简体   繁体   中英

How can I uninstall Hotfix remotely with Powershell

This what I have so far it brings up a Syntax screen for wusa. I have confirmed that the Trim is working. If I leave out the remote computer name is works on the local computer. I will be adding this to a much larger script just trying to get this working before trying to add it.

<#.NAME Template #>

$comp = "Remote Pc Name Goes Here"
$str = $Hotfix_TextBox.Text. Trim("K","B")

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = New-Object System.Drawing.Point(400,400)
$Form.text                       = "Form"
$Form.TopMost                    = $false

$gethotfix                       = New-Object system.Windows.Forms.Button
$gethotfix.text                  = "Get Hotfixes"
$gethotfix.width                 = 120
$gethotfix.height                = 30
$gethotfix.location              = New-Object System.Drawing.Point(100,81)
$gethotfix.Font                  = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$removehotfix                       = New-Object system.Windows.Forms.Button
$removehotfix.text                  = "Remove Hotfix"
$removehotfix.width                 = 120
$removehotfix.height                = 30
$removehotfix.location              = New-Object System.Drawing.Point(100,120)
$removehotfix.Font                  = New-Object System.Drawing.Font('Microsoft Sans Serif',10)

$Hotfix_TextBox                        = New-Object system.Windows.Forms.TextBox
$Hotfix_TextBox.Text                   = ""
$Hotfix_TextBox.multiline              = $false
$Hotfix_TextBox.width                  = 174
$Hotfix_TextBox.height                 = 20
$Hotfix_TextBox.location               = New-Object System.Drawing.Point(12,235)
$Hotfix_TextBox.Font                   = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
<#
$Trimmed_TextBox                        = New-Object system.Windows.Forms.TextBox
#$Trimmed_TextBox.Text                   = "$str"
$Trimmed_TextBox.multiline              = $false
$Trimmed_TextBox.width                  = 174
$Trimmed_TextBox.height                 = 20
$Trimmed_TextBox.location               = New-Object System.Drawing.Point(12,265)
$Trimmed_TextBox.Font                   = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
#>
$Form.controls.AddRange(@($gethotfix,$removehotfix,$Hotfix_TextBox))

$gethotfix.Add_Click({ GetHotfix })
$removehotfix.Add_Click({ RemoveHotfix })

#region Logic 
function GetHotfix {$Hotfix_TextBox.Text = Get-Hotfix -Computername $comp |
        Select-Object -ExpandProperty 'HotFixID'|
           Out-GridView -Title 'Installed Hotfixes' -PassThru }
#$Hotfix_TextBox.Text. Trim("K","B")    
#$Hotfix_TextBox.Text  = "$str"

function RemoveHotfix{
#$Trimmed_TextBox.Text  = "$str"
$comp = "dus-xtdfed9r386"
 #Uninstall-HotFix -ComputerName $comp
  wusa -computername /$comp | /uninstall | /kb:$str 
}

#endregion

[void]$Form.ShowDialog()

This turned out to be a fiasco. Even when I could get it to work there are many KBs that cannot be removed, as well as we had policies that would not allow us to remove many others. Just not worth the effort. Perhaps someone with less strengent policies in place can do something with this. Have Fun.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM