Reporting Installation Status Totals by Update

 

Applies To: Windows Server Update Services

The following example shows how to retrieve the summary installation totals for each approved update. For example, the summary totals indicate the number of clients in the group that have successfully installed the update. Those updates that are not specifically deployed to the given target group are reflected in the UnknownCount summary total (except for those updates that are deployed to the All Computers group, in which case the update will not be reflected in the UnknownCount summary total).

IUpdateServer server = AdminProxy.GetUpdateServer();  
  
//Retrieve each target group.  
foreach (IComputerTargetGroup group in server.GetComputerTargetGroups())  
{  
  //For each group, retrieve the installation totals for each update  
  //approved for deployment.  
  foreach (IUpdateSummary summary in group.GetSummaryPerUpdate())  
  {  
    Console.WriteLine("Group: {0}\nUpdate: {1}\nInstalled: {2}\nPending restart: {3}" +  
                      "\nDownloaded: {4}\nNot installed: {5}\nFailed: {6}\n" +  
                      "\nNot applicable: {7}\nUnknown: {8}\n",   
                      group.Name,    
                      server.GetUpdate(new UpdateRevisionId(summary.UpdateId)).Title,  
                      summary.InstalledCount, summary.InstalledPendingRebootCount,  
                      summary.DownloadedCount, summary.NotInstalledCount,   
                      summary.FailedCount, summary.NotApplicableCount,  
                      summary.UnknownCount);  
  }  
}  

The following example shows how to filter the summary installation totals in the previous example to reflect only those updates that are approved for deployment to the given target group. If the update is approved to clients in the All Computers group, the approval implicitly applies to clients in any group.

IUpdateServer server = AdminProxy.GetUpdateServer();  
IComputerTargetGroup allComputersGroup = null;  
  
//Retrieve each target group.  
foreach (IComputerTargetGroup group in server.GetComputerTargetGroups())  
{  
  int clientCount = group.GetComputerTargets().Count;  //Count of clients in the group  
  
  //If the group does not contain clients, do not report the status.  
  if (clientCount > 0)   
  {          
    //Retrieve the summary installation information for each update.  
    foreach (IUpdateSummary summary in group.GetSummaryPerUpdate())  
    {  
      bool deployedToThisGroup = false;  //Approved for deployment to clients in this group  
      IUpdate update = server.GetUpdate(new UpdateRevisionId(summary.UpdateId));  
  
      if (null == allComputersGroup) //Retrieve the All Computers group only once.  
      {  
        allComputersGroup = server.GetComputerTargetGroup(ComputerTargetGroupId.AllComputers);  
      }  
  
      //Determine if the update was approved for deployment to this group or   
      //the All Computers group. If the update is approved to the All Computers  
      //group, make sure that it is not also approved to block deployment to this group.  
      if (update.GetUpdateApprovals(group).Count > 0)  
      {  
        if (update.GetUpdateApprovals(group, UpdateApprovalAction.Block, DateTime.MinValue, DateTime.MaxValue).Count == 0)  
          deployedToThisGroup = true;  
      }  
      else if (update.GetUpdateApprovals(allComputersGroup).Count > 0)  
      {  
          deployedToThisGroup = true;  
      }  
  
      if (true == deployedToThisGroup)  
      {  
        Console.WriteLine("Group: {0}\nUpdate: {1}\nInstalled: {2}\nPending restart: {3}" +  
                      "\nDownloaded: {4}\nNot installed: {5}\nFailed: {6}\n" +  
                      "\nNot applicable: {7}\nUnknown: {8}\n",   
                      group.Name, update.Title,  
                      summary.InstalledCount, summary.InstalledPendingRebootCount,  
                      summary.DownloadedCount, summary.NotInstalledCount,   
                      summary.FailedCount, summary.NotApplicableCount,  
                      summary.UnknownCount);  
      }   
    }  
  }  
}