예제 #1
0
        /// <summary>
        /// Displays a list of target groups and their guids
        /// </summary>
        /// <param name="targetGroup">a target group</param>
        static void ListTargetGroups(
            Microsoft.UpdateServices.Administration.IComputerTargetGroup targetGroup
            )
        {
            System.Console.Out.WriteLine(targetGroup.Id + "\t" + targetGroup.Name);
            Microsoft.UpdateServices.Administration.ComputerTargetGroupCollection children
                = targetGroup.GetChildTargetGroups();

            if (children == null || children.Count <= 0)
            {
                return;
            }

            foreach (Microsoft.UpdateServices.Administration.IComputerTargetGroup child in children)
            {
                ListTargetGroups(child);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(
            string[] args
            )
        {
            ShowHeader();

            if (args == null ||
                args.GetLength(0) == 0)
            {
                ShowHelp();
                return;
            }

            Controller.CommandLine commandLine = new Controller.CommandLine(args);
            if (commandLine.GetWantsHelp())
            {
                ShowHelp();
                return;
            }

            //Connect to server
            System.String         hostname           = commandLine.GetHostname();
            SmartLib.Model.Server connectionSettings = (hostname == null) ?
                                                       null :
                                                       new SmartLib.Model.Server();
            if (connectionSettings != null)
            {
                connectionSettings.Hostname = hostname;
                connectionSettings.Port     = commandLine.GetPort();
                connectionSettings.Secure   = commandLine.GetSecure();
            }

            Microsoft.UpdateServices.Administration.IUpdateServer server
                = SmartLib.Controller.Server.Connect(connectionSettings);

            //Check user has admin or reporter access
            Microsoft.UpdateServices.Administration.UpdateServerUserRole role = server.GetCurrentUserRole();
            if (role != Microsoft.UpdateServices.Administration.UpdateServerUserRole.Reporter &&
                role != Microsoft.UpdateServices.Administration.UpdateServerUserRole.Administrator)
            {
                throw new System.UnauthorizedAccessException("You don't have reporter or administrator access on the WSUS server.");
            }


            //Get Classifications
            System.Console.Out.WriteLine("Getting classifications.");
            Microsoft.UpdateServices.Administration.UpdateClassificationCollection classifications =
                SmartLib.Controller.Server.GetUpdateClassifications(server);

            //Get product categories
            System.Console.Out.WriteLine("Getting product categories.");
            Microsoft.UpdateServices.Administration.UpdateCategoryCollection categories
                = SmartLib.Controller.Server.GetRootUpdateCategories(server);

            //Get target groups
            System.Console.Out.WriteLine("Getting root target group.");
            Microsoft.UpdateServices.Administration.IComputerTargetGroup rootGroup
                = SmartLib.Controller.Server.GetRootTargetGroup(server);

            System.Console.Out.WriteLine("\nClassifications:\n");
            ListClassifications(classifications);
            System.Console.Out.WriteLine("\nProduct Categories:\n");
            ListCategories(categories, 0);
            System.Console.Out.WriteLine("\nTarget Groups:\n");
            ListTargetGroups(rootGroup);
        }