Exemplo n.º 1
0
 /// <summary>
 /// Displays a list of classifications and their guids
 /// </summary>
 /// <param name="classifications">classifications</param>
 static void ListClassifications(
     Microsoft.UpdateServices.Administration.UpdateClassificationCollection classifications
     )
 {
     foreach (Microsoft.UpdateServices.Administration.IUpdateClassification classification in classifications)
     {
         System.Console.Out.WriteLine(classification.Id + "\t" + classification.Title);
     }
 }
Exemplo n.º 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);
        }