共用方式為


Script: Bulk approve WSUS updates from CSV input file

Hope this script will help someone out there! 

# Script

# Author: Johan Vosloo
# Date: 16-10-2009
# Purpose: Bulk approve updates by specifying the UpdateID, WSUS Group Name and a Computer Name (any computer that is a member of the applicable group).
# Disclaimer: This script is provided as-is without any support. Script was tested on WSUS 3.0 SP1 and using Powershell 1.0. Please test in a test environment before production use.
# Credit: Adapted from https://gallery.technet.microsoft.com/ScriptCenter/en-us/e3b33372-1e7f-41ea-ad83-ecc10ba5f0f6
# CSV Example:
## updateID,grp,cName
## 82aa7a7a-c2c3-47b4-ab32-cb35c0e41ffc,Group2,wsus.labrootad.local
## 82aa7a7a-c2c3-47b4-ab32-cb35c0e41ffc,Group3,wsus.labrootad.local

# Specify path to CSV and ensure CSV is similar to example.
$path = "C:\Temp\Test.csv";

[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null;
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
Import-csv -path $path | foreach `
{
    $groupName = $_.grp;
    $computerName = $_.cName;
    $UId = $_.updateID;
   
    # Use '$false' to return CSV-specified update information only. That is, updates will not be approved.
    $approveUpdates = $true;
    #$approveUpdates = $false;
   
    $group = $null;
    $computer = $wsus.GetComputerTargetByName($computerName);
    $groups = $computer.GetComputerTargetGroups() | foreach `
    {
    If ($_.Name  -eq  $groupName) {$group = $_};
 };
    if ($group -eq $null) {throw new-object System.Exception($computerName + " is not a member of group: " + $groupName)};
   
    # Use UpdateScope to 'filter' the list that will be used to match the CSV-specified UpdateId.
    $updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
    #IncludedInstallationStates [eg. All/Downloaded/Failed/Installed/NotInstalled/InstalledPendingReboot/NotApplicable/Unknown] - https://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration.updateinstallationstates(VS.85).aspx
    $updateScope.IncludedInstallationStates = "All";
    #ApprovedStates [eg. Any/Declined/HasStaleUpdateApprovals/LatestRevisionApproved/NotApproved] - https://msdn.microsoft.com/en-us/library/bb313233(VS.85).aspx
    $updateScope.ApprovedStates = "Any";
   
    $action = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install;
    $updates = $computer.GetUpdateInstallationInfoPerUpdate($updateScope);
    $updates | foreach `
    {
        If ($_.UpdateId -eq $UId)
        {
        $u = $wsus.GetUpdate($_.UpdateId);
        #Properties [Title/State/Etc] - https://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration.iupdate_members(VS.85).aspx
        Write-Host "Processing UpdateID: " $_.UpdateId;
        If ($approveUpdates) {$u.Approve($action,$group) | out-null}
        else {Write-host “Need to approve:" $u.Title};
        };
    };
};