使用powershell删除日期为的windows update软件包

使用powershell删除日期为的windows update软件包,powershell,Powershell,我有一项任务要求我删除特定日期的所有windowsupdatepackages。 我甚至制作了一个脚本,使用给定的KB数一次删除一个包。我现在陷入困境,不知道该怎么办,这是我的代码: function Uninstall-Hotfix { [cmdletbinding()] param( $computerName = $env:computername, [string] $hotFixId ) $hotFixes = Get-

我有一项任务要求我删除特定日期的所有windowsupdatepackages。 我甚至制作了一个脚本,使用给定的KB数一次删除一个包。我现在陷入困境,不知道该怎么办,这是我的代码:

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
    }
}

使用日期对象作为输入参数,而不是使用hotfixId字符串作为参数。然后让函数将提供给函数的日期与$hotfix的日期进行比较。Win32_QuickFixEngineering类具有可用于此比较的InstalledOn属性。如果日期匹配,则卸载修补程序。如何做到这一点的确切细节是你的家庭作业,但如果你在某一点上陷入困境,请问另一个问题

请参阅Win32_QuickFixEngineering类的文档:


你有什么问题?我应该怎么做才能让它根据日期删除所有包?你提到你被卡住了。你在坚持什么?我们可以帮你做作业。我们不能做你的家庭作业。当你运行脚本时,你看到了什么?这可能有助于我们了解您的困境。它不会给我错误消息或任何东西。它起作用了。我只需要知道我能做些什么,让它删除某个日期的所有包,而不是一次只删除一个包谢谢!现在我至少知道从哪里开始寻找:)