2017-10-19 17 views
0

업데이트를 제거하는 powershell 스크립트를 작성하려고합니다.wusa.exe를 사용하여 업데이트 제거

내 문제는 스크립트가 시작될 때 wusa.exe 스크립트가 실행되지 않는다는 것입니다.

function Uninstall-Hotfix() { 
    [string]$parameters = "KB4041691" 
    [string]$KBs = @() 

    if ($parameters.Contains(":")) { 
     [object]$arguments = $parameters.Split(":") 
     foreach ($argument in $arguments) { 
      $argument.Replace("KB", "") 
      $KBs.add($argument) 

      for ($i = 0; $i -lt $KBs.length; $i++) { 
       Cmd /c wusa.exe /uninstall /KB:$KBs[$i] /quiet /norestart 
       Do { 
        Start-Sleep -Seconds 3 
       } 
       while (Wait-Process | Where-Object {$_.name -eq "wusa"}) 

       If (Get-Hotfix -Id $KBs[$i] -ErrorAction SilentlyContinue) { 
        Write-Host "KB $KBs[$i] Fehlerhaft" 
       } 
       Else { 
        Write-Host "KB $KBs[$i] Erfolgreich deinstalliert" 
       } 
      } 
     } 
    } 
    Else { 
     $parameter = $parameters.Replace("KB", "") 
     $parameter 
     cmd /c wusa.exe /uninstall /KB:$parameter /quiet /norestart 
     Do { 
      Start-Sleep -Seconds 3 
     } 
     while (Wait-Process | Where-Object {$_.name -eq "wusa.exe"}) 
    } 
} 
Uninstall-Hotfix 
+0

cmd를 명령하지 않은 오류 메시지를 참조하십시오. 시작 프로세스를 사용하거나 wusa.exe를 직접 호출하십시오. – guiwhatsthat

+0

시도해보십시오. & wusa.exe/uninstall/KB : $ parameter/quiet/norestart' –

+0

@guiwhatsthat : Powershell은 오류를 표시하지 않고 "cmd"명령을 사용하여 다른 스크립트를 보았습니다. – MRed

답변

0

코드는 매우 무거운이고 내 생각이 너무 많은 루프를 포함, 당신이 시도 할 수 있습니다 :

function Uninstall-Hotfix() { 
    Param(
     [Parameter(Mandatory=$true)][array]$Patches 
    ) 

    foreach($patch in $Patches){ 
     $numKb = $null 
     if($patch -match "\d{7}"){ 
      [int]$numkb = $Matches[0] 
      Write-Host $numKb 

      Start-Process wusa.exe -ArgumentList "/KB:$numKb /uninstall /quiet /norestart" -Wait 

      if(Get-Hotfix -Id $numKb -ErrorAction SilentlyContinue){ 
       Write-Host "KB $KBs[$i] Fehlerhaft" 
      } 
      else{ 
       Write-Host "KB $KBs[$i] Erfolgreich deinstalliert" 
      } 
     } 
     else{ 
      Write-Host "KB is not valid" 
     } 
    } 
} 
Uninstall-Hotfix -Patches KB4041691,KB1234567 
+0

고마워요.하지만이 여전히 작동하지 않습니다. "/ 조용히"매개 변수를 사용하지 않을 때 wusa 열고 묻습니다. 나는 그것을 제거하고 싶다. "/ quiet"매개 변수를 사용할 때 그는 아무 것도하지 않고 wusa 프로세스를 볼 수 없다. 왜 이것이 작동하지 않는지? 감사합니다. – MRed

+0

PowerShell 문제 : Windows 10 사용자는이 게시물을 살펴볼 수 있습니다. https://social.technet.microsoft.com/F orums/windows/en-US/f6594e00-2400-4276-85a1-fb06485b53e6/issues-with-wusaexe-and-windows-10-enterprise? forum = win10itprogeneral – Manu

+0

우리는 원격 모니터링 및 관리를 사용하여 스크립트를 기계는 Windows 7을 사용합니다.) 그러나 "/ quiet"스위치를 사용할 수없는 경우에는 사용할 수 없습니다 ... "/ uninstall/kb : .."스위치를 사용하면 " /조용한". 그러나 "/ uninstall "스위치를 사용하면 "/ quiet"스위치를 사용할 수 있습니다. 그러나 이것이 의 의미는 무엇입니까? 매개 변수없이 wusa.exe를 열면 사용 가능한 매개 변수가 표시됩니다 ... – MRed