Reporting Updates Needed by Clients
Applies To: Windows Server Update Services
To determine if an update is needed by clients, the update must have been approved for deployment to one or more clients. For details, see Approving Deployment of an Update to a Group of Computers. After the clients have had time to report status back to the WSUS server, you can call one of the following methods to determine if an update is needed by one or more clients in the group:
IComputerTargetGroup.GetUpdateInstallationInfoPerComputerTarget(IUpdate)
IUpdate.GetUpdateInstallationInfoPerComputerTarget(IComputerTargetGroup)
The update is needed if the IUpdateInstallationInfo.UpdateInstallationState is NotInstalled, Failed, Downloaded, or InstalledPendingReboot as shown in the following example. If the update is approved for scanning, the client returns NotInstalled if the update is applicable.
The following example shows how to determine those updates that are needed by one or more clients.
IUpdateServer server = AdminProxy.GetUpdateServer();
UpdateInstallationInfoCollection installInfoCollection = null;
IComputerTargetGroup allComputersGroup = server.GetComputerTargetGroup(ComputerTargetGroupId.AllComputers);
StringCollection clientNames = new StringCollection();
int totalUpdatesNeeded = 0;
//Retrieve each update.
foreach (IUpdate update in server.GetUpdates())
{
//Retrieve the update installation information for each client.
installInfoCollection = update.GetUpdateInstallationInfoPerComputerTarget(allComputersGroup);
//For each client, determine if the client needs the update.
foreach (IUpdateInstallationInfo installInfo in installInfoCollection)
{
if (UpdateInstallationState.NotInstalled == installInfo.UpdateInstallationState ||
UpdateInstallationState.Failed == installInfo.UpdateInstallationState ||
UpdateInstallationState.Downloaded == installInfo.UpdateInstallationState ||
UpdateInstallationState.InstalledPendingReboot == installInfo.UpdateInstallationState)
{
clientNames.Add(installInfo.GetComputerTarget().FullDomainName);
}
}
//If any of the clients need the update, increment the totalUpdatesNeeded counter.
if (clientNames.Count > 0)
{
totalUpdatesNeeded++;
//Print the update and the list of clients that need to install the update.
Console.WriteLine("{0} needed by:", update.Title);
foreach (String name in clientNames)
{
Console.WriteLine("{0}", name);
}
Console.WriteLine();
clientNames.Clear();
}
}
Console.WriteLine("\n{0} updates needed by clients.", totalUpdatesNeeded);
The following example shows how to determine those updates that a client needs.
IUpdateServer server = AdminProxy.GetUpdateServer();
StringCollection updateTitles = new StringCollection();
//Retrieve each client.
foreach (IComputerTarget client in server.GetComputerTargets())
{
Console.WriteLine("{0} needs the following updates:", client.FullDomainName);
//Retrieve the update installation information for each update.
foreach (IUpdateInstallationInfo installInfo in client.GetUpdateInstallationInfoPerUpdate())
{
//For each update, determine if the client needs the update.
if (UpdateInstallationState.NotInstalled == installInfo.UpdateInstallationState ||
UpdateInstallationState.Failed == installInfo.UpdateInstallationState ||
UpdateInstallationState.Downloaded == installInfo.UpdateInstallationState ||
UpdateInstallationState.InstalledPendingReboot == installInfo.UpdateInstallationState)
{
updateTitles.Add(installInfo.GetUpdate().Title);
}
}
if (0 == updateTitles.Count)
{
Console.WriteLine("\tNone\n");
}
else
{
foreach (String title in updateTitles)
{
Console.WriteLine("\t{0}", title);
}
Console.WriteLine();
updateTitles.Clear();
}
}
You can also call UpdateServerStatus.ComputerTargetsNeedingUpdatesCount and UpdateServerStatus.UpdatesNeededByComputersCount to retrieve this information.