/// <summary> /// Checks a classification for needed updates /// </summary> /// <param name="server"> /// Object representing the WSUS server /// </param> /// <param name="classification"> /// a single update classification /// </param> /// <param name="rootGroup"> /// the "all computers" group /// </param> /// <param name="isTest"> /// Whether we are in test mode /// </param> /// <param name="alreadyProcessed"> /// List of target groups that have already been processed /// </param> private static void CheckClassification( IUpdateServer server, IUpdateClassification classification, IComputerTargetGroup rootGroup, bool isTest, List <IComputerTargetGroup> alreadyProcessed) { Console.Out.WriteLine("Getting list of updates for : " + classification.Title); var searchScope = new UpdateScope { IncludedInstallationStates = UpdateInstallationStates.NotInstalled }; searchScope.Classifications.Add(classification); UpdateCollection updates = server.GetUpdates(searchScope); if (updates.Count > 0) { DoClassificationUpdates(updates, rootGroup, isTest, alreadyProcessed); } else { Console.Out.WriteLine(" No updates required."); } }
/// <summary> /// checks for superseded updates and approves the new revision /// </summary> /// <param name="server"> /// The WSUS Server /// </param> /// <param name="approveLicenseAgreement"> /// Whether to approve any license agreement /// </param> /// <param name="computerTargetGroup"> /// The target group to check /// </param> /// <param name="classification"> /// Classification to process /// </param> /// <param name="products"> /// Collection of products to process /// </param> /// <param name="isTest"> /// Whether we are in test mode /// </param> /// <param name="shouldApproveUninstalledSupersededUpdate"> /// The should Approve Uninstalled Superseded Update. /// </param> private static void CheckSupersededUpdates( IUpdateServer server, bool approveLicenseAgreement, IComputerTargetGroup computerTargetGroup, IUpdateClassification classification, UpdateCategoryCollection products, bool isTest, bool shouldApproveUninstalledSupersededUpdate) { var searchScope = new UpdateScope { ApprovedStates = ApprovedStates.HasStaleUpdateApprovals }; if (computerTargetGroup != null) { searchScope.ApprovedComputerTargetGroups.Add(computerTargetGroup); } if (classification != null) { searchScope.Classifications.Add(classification); } if (products != null) { searchScope.Categories.AddRange(products); } UpdateCollection updates = server.GetUpdates(searchScope); if (updates.Count <= 0) { return; } var recentlyApproved = new List <Guid>(); if (updates.Count == 0) { Console.Out.WriteLine(" No updates required."); return; } foreach (IUpdate update in updates) { if (update.IsSuperseded) { CheckSupersededUpdate( update, approveLicenseAgreement, isTest, recentlyApproved, shouldApproveUninstalledSupersededUpdate); } } }
/// <summary> /// The do run set classification. /// </summary> /// <param name="server"> /// Object representing the WSUS server /// </param> /// <param name="computerTargetGroup"> /// The target group to check /// </param> /// <param name="classification"> /// </param> /// <param name="isTest"> /// Whether we are in test mode /// </param> /// <param name="alreadyProcessed"> /// List of target groups that have already been processed /// </param> private static void DoRunSetClassification( IUpdateServer server, IComputerTargetGroup computerTargetGroup, Classification classification, bool isTest, List <IComputerTargetGroup> alreadyProcessed) { // check the classification exists on wsus IUpdateClassification uc = server.GetUpdateClassification(classification.Guid); // check for a product collection UpdateCategoryCollection products = classification.Products.ElementInformation.IsPresent ? GetUpdateCategoryCollection(server, classification.Products) : null; if (classification.ApproveStaleUpdates) { CheckStaleUpdates( server, classification.AcceptLicenseAgreement, computerTargetGroup, uc, products, isTest); } if (classification.ApproveSupersededUpdates) { CheckSupersededUpdates( server, classification.AcceptLicenseAgreement, computerTargetGroup, uc, products, isTest, classification.ShouldApproveUninstalledSupersededUpdate); } if (classification.ApproveNeededUpdates) { CheckClassification(server, uc, computerTargetGroup, isTest, alreadyProcessed); } }
/// <summary> /// Checks for updates that may have a new revision /// </summary> /// <param name="server"> /// The WSUS Server /// </param> /// <param name="approveLicenseAgreement"> /// Whether to approve any license agreement /// </param> /// <param name="computerTargetGroup"> /// The target group to check /// </param> /// <param name="classifications"> /// Classification to process /// </param> /// <param name="products"> /// Collection of products to process /// </param> /// <param name="isTest"> /// Whether we are in test mode /// </param> private static void CheckStaleUpdates( IUpdateServer server, bool approveLicenseAgreement, IComputerTargetGroup computerTargetGroup, IUpdateClassification classifications, UpdateCategoryCollection products, bool isTest) { var searchScope = new UpdateScope { ApprovedStates = ApprovedStates.HasStaleUpdateApprovals }; if (computerTargetGroup != null) { searchScope.ApprovedComputerTargetGroups.Add(computerTargetGroup); } if (classifications != null) { searchScope.Classifications.Add(classifications); } if (products != null) { searchScope.Categories.AddRange(products); } UpdateCollection updates = server.GetUpdates(searchScope); if (updates.Count > 0) { foreach (IUpdate update in updates) { CheckStaleUpdate(update, isTest, approveLicenseAgreement); } } else { Console.Out.WriteLine(" No updates required."); } }
/// <summary> /// checks for superseded updates and approves the new revision /// </summary> /// <param name="server"> /// The WSUS Server /// </param> /// <param name="approveLicenseAgreement"> /// Whether to approve any license agreement /// </param> /// <param name="computerTargetGroup"> /// The target group to check /// </param> /// <param name="classification"> /// Classification to process /// </param> /// <param name="products"> /// Collection of products to process /// </param> /// <param name="isTest"> /// Whether we are in test mode /// </param> /// <param name="shouldApproveUninstalledSupersededUpdate"> /// The should Approve Uninstalled Superseded Update. /// </param> private static void CheckSupersededUpdates( IUpdateServer server, bool approveLicenseAgreement, IComputerTargetGroup computerTargetGroup, IUpdateClassification classification, UpdateCategoryCollection products, bool isTest, bool shouldApproveUninstalledSupersededUpdate) { var searchScope = new UpdateScope { ApprovedStates = ApprovedStates.HasStaleUpdateApprovals }; if (computerTargetGroup != null) { searchScope.ApprovedComputerTargetGroups.Add(computerTargetGroup); } if (classification != null) { searchScope.Classifications.Add(classification); } if (products != null) { searchScope.Categories.AddRange(products); } UpdateCollection updates = server.GetUpdates(searchScope); if (updates.Count <= 0) { return; } var recentlyApproved = new List<Guid>(); if (updates.Count == 0) { Console.Out.WriteLine(" No updates required."); return; } foreach (IUpdate update in updates) { if (update.IsSuperseded) { CheckSupersededUpdate( update, approveLicenseAgreement, isTest, recentlyApproved, shouldApproveUninstalledSupersededUpdate); } } }
/// <summary> /// Checks a classification for needed updates /// </summary> /// <param name="server"> /// Object representing the WSUS server /// </param> /// <param name="classification"> /// a single update classification /// </param> /// <param name="rootGroup"> /// the "all computers" group /// </param> /// <param name="isTest"> /// Whether we are in test mode /// </param> /// <param name="alreadyProcessed"> /// List of target groups that have already been processed /// </param> private static void CheckClassification( IUpdateServer server, IUpdateClassification classification, IComputerTargetGroup rootGroup, bool isTest, List<IComputerTargetGroup> alreadyProcessed) { Console.Out.WriteLine("Getting list of updates for : " + classification.Title); var searchScope = new UpdateScope { IncludedInstallationStates = UpdateInstallationStates.NotInstalled }; searchScope.Classifications.Add(classification); UpdateCollection updates = server.GetUpdates(searchScope); if (updates.Count > 0) { DoClassificationUpdates(updates, rootGroup, isTest, alreadyProcessed); } else { Console.Out.WriteLine(" No updates required."); } }