/// <summary> /// Displays a list of products categories and their guids /// </summary> /// <param name="categories">categories</param> /// <param name="depthCount">How deep in we have iterated, used for console output</param> static void ListCategories( Microsoft.UpdateServices.Administration.UpdateCategoryCollection categories, int depthCount ) { foreach (Microsoft.UpdateServices.Administration.IUpdateCategory category in categories) { for (int i = 0; i < depthCount; i++) { System.Console.Out.Write(" "); } System.Console.Out.WriteLine(category.Id + "\t" + category.Title); Microsoft.UpdateServices.Administration.UpdateCategoryCollection subCategories = category.GetSubcategories(); if (subCategories != null && subCategories.Count > 0) { ListCategories(subCategories, depthCount + 1); } } }
/// <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); }