2017-11-15 2 views
-2

特定の日付のすべてのwindowsupdateパッケージを削除したいという課題があります。 私は、指定されたKB番号を使って一度に1つのパッケージを削除するスクリプトを作成するまで来ました。私は今、立ち往生し、何をすべきかを知らないのです、ここに私のコードは次のとおりです。代わりにパラメータとしてhotfixId文字列を使用してのpowershellを使用して日付上にWindowsアップデートパッケージを削除する

function Uninstall-Hotfix { 
    [cmdletbinding()] 
    param(
     $computerName = $env:computername, 
     [string] $hotFixId 
    ) 

    $hotFixes = Get-WmiObject -ComputerName $computerName -Class Win32_QuickFixEngineering | select hotfixid 

    $date = Get-Date 

    Write-Host "deleted on '$date'" 

    if ($hotFixes -match $hotFixId) { 
     $hotFixId = $hotFixId.Replace("KB", "") 
     Write-Host "found hotfix" + $hotFixId 
     Write-Host "Uninstalling the hotflix" 
     $uninstallString = "cmd.exe /c  wusa.exe /uninstall /KB:$hotFixId /quiet /norestart" 
     ([WMICLASS]"\\$computerName\ROOT\CIMV2:win32_process").Create($uninstallString) | out-null 

     while (@(Get-Process wusa -ComputerName $computerName -ErrorAction SilentlyContinue).Count -ne 0) { 
      Start-Sleep 3 
      Write-Host "Waiting for update removal to finish ..." 
     } 
     Write-Host "Completed uninstalling of $hotFixId" 
    } 
    else { 
     Write-Host "Given hotfix($hotFixId) not found" 
     return 
    } 
} 
+1

あなたの質問は何ですか? –

+0

日付に基づいてすべてのパッケージを削除するにはどうすればよいですか? –

+0

あなたはあなたが立ち往生していると言います。あなたは何をしていますか?あなたの宿題を手伝うことができます。あなたの宿題はできません。 –

答えて

0

、入力パラメータとして日付オブジェクトを使用します。関数に与えられた日付を$ hotfixの日付と比較させる。 Win32_QuickFixEngineeringクラスには、この比較に使用できるInstalledOnプロパティがあります。日付が一致する場合は、修正プログラムをアンインストールします。これを行う方法の正確な詳細はあなたの宿題ですが、特定の点にこだわると別の質問をします。

はのWin32_QuickFixEngineeringクラスのドキュメントを参照してください:

https://msdn.microsoft.com/en-us/library/aa394391(v=vs.85).aspx

+0

ありがとう!今私はatleastはどこから見始めて知っている:) –

関連する問題