Esempio n. 1
0
        /// <summary>
        /// The check needed updates.
        /// </summary>
        /// <param name="server">
        /// </param>
        /// <param name="ctg">
        /// </param>
        /// <param name="isTest">
        /// </param>
        private static void CheckNeededUpdates(
            IUpdateServer server,
            IComputerTargetGroup ctg,
            // Microsoft.UpdateServices.Administration.UpdateCategoryCollection products,
            bool isTest)
        {
            // check classifications
            Console.Out.WriteLine("Getting classifications");
            UpdateClassificationCollection classifications = Server.GetUpdateClassifications(server);

            // check for updates
            foreach (IUpdateClassification classification in classifications)
            {
                CheckClassification(server, classification, ctg, isTest, null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The do run set all target groups.
        /// </summary>
        /// <param name="server">
        /// </param>
        /// <param name="allTargetGroups">
        /// </param>
        /// <param name="isTest">
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetAllTargetGroups(
            IUpdateServer server,
            AllTargetGroups allTargetGroups,
            bool isTest,
            List <IComputerTargetGroup> alreadyProcessed)
        {
            Console.Out.WriteLine("Getting root target group: ");
            IComputerTargetGroup rootGroup = Server.GetRootTargetGroup(server);

            ClassificationCollection classifications = allTargetGroups.Classifications;

            if (classifications.Count > 0)
            {
                DoRunSetClassifications(server, rootGroup, classifications, isTest, alreadyProcessed);
            }
            else
            {
                DoRunSetAllClassifications(server, rootGroup, isTest, allTargetGroups.AllClassifications);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This is the path run if there are no run sets in the app.config
        ///     This is the classic apply to all groups approach from 1.0.0.0
        /// </summary>
        /// <param name="settings">
        /// application settings
        /// </param>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void DoNoRunSets(ApplicationSettings settings, IUpdateServer server, bool isTest)
        {
            Console.WriteLine("Performing \"No Run Set\" rule: ");

            // Get target groups
            Console.Out.WriteLine("Getting root target group: ");
            IComputerTargetGroup rootGroup = Server.GetRootTargetGroup(server);

            Console.Out.WriteLine("succeeded.");

            Rule defaultRule = settings.NoRunSet;

            if (defaultRule.ApproveSupersededUpdates)
            {
                // Check for superseded updates
                Console.Out.WriteLine("Checking Superseded Updates: ");
                CheckSupersededUpdates(
                    server,
                    defaultRule.AcceptLicenseAgreement,
                    null,
                    null,
                    null,
                    isTest,
                    defaultRule.ShouldApproveUninstalledSupersededUpdate);
            }

            if (defaultRule.ApproveStaleUpdates)
            {
                // Check for stale updates
                Console.Out.WriteLine("Checking Stale Updates: ");
                CheckStaleUpdates(server, defaultRule.AcceptLicenseAgreement, null, null, null, isTest);
            }

            if (defaultRule.ApproveNeededUpdates)
            {
                CheckNeededUpdates(server, rootGroup, isTest);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <exception cref="UnauthorizedAccessException">
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        public void Execute()
        {
            ShowHeader();

            string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();
            if (!args.Any())
            {
                ShowHelp();
                return;
            }

            var commandLine = new CommandLine(args);

            if (commandLine.GetWantsHelp())
            {
                ShowHelp();
                return;
            }

            // todo: add support for job monitoring

            // Check config file
            ApplicationSettings settings = LoadSettings();

            // Connect to server
            IUpdateServer server = Server.Connect(settings.Server);

            // Check user has admin access
            UpdateServerUserRole role = server.GetCurrentUserRole();

            if (role != UpdateServerUserRole.Administrator)
            {
                throw new UnauthorizedAccessException("You don't have administrator access on the WSUS server.");
            }

            // Get the default rule
            bool             isTest  = commandLine.GetIsTest();
            RunSetCollection runSets = settings.RunSets;

            switch (commandLine.GetUseRunSet())
            {
            case TriState.Yes:
                if (runSets == null || runSets.Count == 0)
                {
                    throw new InvalidOperationException(
                              "/runset specified on the command line.  But there are no runsets defined in the config file.");
                }

                // we have run sets
                // this means our approval logic is more complex
                DoRunSets(server, runSets, commandLine, isTest);

                break;

            case TriState.No:
                DoNoRunSets(settings, server, isTest);

                break;

            default:
                if (runSets != null && runSets.Count > 0)
                {
                    throw new InvalidOperationException(
                              "RunSets exist in the application config. /norunset or /runset must be specified on the command line.");
                }

                break;
            }
        }