ComputerTargetCollection Class

 

Applies To: Windows Server Update Services

Represents a collection of client computers.

Namespace:   Microsoft.UpdateServices.Administration
Assembly:  Microsoft.UpdateServices.Administration (in Microsoft.UpdateServices.Administration.dll)

System.Object
  System.Collections.CollectionBase
    Microsoft.UpdateServices.Administration.WsusCollection
      Microsoft.UpdateServices.Administration.ComputerTargetCollection

[SerializableAttribute]
[GuidAttribute("E21D4DAF-A20B-4CAF-A111-F4A66C223628")]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
public class ComputerTargetCollection : WsusCollection

NameDescription
System_CAPS_pubmethodComputerTargetCollection()

Initializes a new instance of the ComputerTargetCollection class.

NameDescription
System_CAPS_pubpropertyCapacity

(Inherited from CollectionBase.)

System_CAPS_pubpropertyCount

(Inherited from CollectionBase.)

System_CAPS_protpropertyInnerList

(Inherited from CollectionBase.)

System_CAPS_pubpropertyItem[Int32]

Retrieve or set the element at the specified index.

System_CAPS_protpropertyList

(Inherited from CollectionBase.)

NameDescription
System_CAPS_pubmethodAdd(IComputerTarget)

Adds a client computer to the end of the collection.

System_CAPS_protmethodAdd(Object)

Adds an element to the end of the collection.(Inherited from WsusCollection.)

System_CAPS_protmethodAddRange(Array)

Adds the elements of the specified array to the end of this collection. (Inherited from WsusCollection.)

System_CAPS_pubmethodAddRange(ComputerTargetCollection)

Adds the members of a collection of computers to the end of this collection.

System_CAPS_pubmethodAddRange(IComputerTarget[])

Adds the elements of a ComputerTarget array to the end of this collection.

System_CAPS_protmethodAddRange(WsusCollection)

Adds the items in the specified SusCollectionBase to the end of this collection.(Inherited from WsusCollection.)

System_CAPS_pubmethodClear()

(Inherited from CollectionBase.)

System_CAPS_pubmethodContains(IComputerTarget)

Determines whether the specified ComputerTarget is in the ComputerTargetCollection.

System_CAPS_protmethodContains(Object)

Determines whether the specified element is in the collection.(Inherited from WsusCollection.)

System_CAPS_protmethodCopyTo(Array, Int32)

Copies the entire collection of values to a one-dimensional array, starting at the specified index of the target array.(Inherited from WsusCollection.)

System_CAPS_pubmethodCopyTo(IComputerTarget[], Int32)

Copies the client computers in the collection to a one-dimensional array.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

(Inherited from CollectionBase.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodIndexOf(IComputerTarget)

Determines if the collection contains the specified client computer. If the collection contains the client, the method returns the zero-based index to the client computer in the collection.

System_CAPS_protmethodIndexOf(Object)

Searches for the specified element and returns the zero-based index of it if it exists.(Inherited from WsusCollection.)

System_CAPS_pubmethodInsert(Int32, IComputerTarget)

Inserts a ComputerTarget into the ComputerTargetCollection at the specified index.

System_CAPS_protmethodInsert(Int32, Object)

Inserts an element into the collection at the specified index.(Inherited from WsusCollection.)

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_protmethodOnClear()

(Inherited from CollectionBase.)

System_CAPS_protmethodOnClearComplete()

Performs additional custom processes after clearing the contents of the UpdateCollection instance.(Inherited from WsusCollection.)

System_CAPS_protmethodOnInsert(Int32, Object)

Provides overridden validation functionality which checks that we do not insert duplicates into our collection.(Inherited from WsusCollection.)

System_CAPS_protmethodOnInsertComplete(Int32, Object)

Performs additional custom processes after inserting a new element into the UpdateCollection instance.(Inherited from WsusCollection.)

System_CAPS_protmethodOnRemove(Int32, Object)

(Inherited from CollectionBase.)

System_CAPS_protmethodOnRemoveComplete(Int32, Object)

Performs additional custom processes after removing an element from the UpdateCollection instance.(Inherited from WsusCollection.)

System_CAPS_protmethodOnSet(Int32, Object, Object)

Provices overridden validation functionality which checks that we do not insert duplicates into our collection.(Inherited from WsusCollection.)

System_CAPS_protmethodOnSetComplete(Int32, Object, Object)

Performs additional custom processes after setting a value in the UpdateCollection instance.(Inherited from WsusCollection.)

System_CAPS_protmethodOnValidate(Object)

(Inherited from CollectionBase.)

System_CAPS_pubmethodRemove(IComputerTarget)

Removes a client computer from the collection.

System_CAPS_protmethodRemove(Object)

Removes a specified element from the collection.(Inherited from WsusCollection.)

System_CAPS_pubmethodRemoveAt(Int32)

(Inherited from CollectionBase.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

To retrieve a collection of client computers, call one of the following methods:

/*----------------------------------------------------------------------
This file is part of the Microsoft Windows Server Update Services
API Code Samples.

Copyright (C) Microsoft.  All rights reserved.

DISCLAIMER OF WARRANTY: THIS CODE AND INFORMATION ARE PROVIDED “AS-IS.”  
YOU BEAR THE RISK OF USING IT.  MICROSOFT GIVES NO EXPRESS WARRANTIES, 
GUARANTEES OR CONDITIONS.  YOU MAY HAVE ADDITIONAL CONSUMER RIGHTS 
UNDER YOUR LOCAL LAWS WHICH THIS AGREEMENT CANNOT CHANGE.  
TO THE EXTENT PERMITTED UNDER YOUR LOCAL LAWS, MICROSOFT EXCLUDES 
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
PURPOSE AND NON-INFRINGEMENT.
----------------------------------------------------------------------*/

namespace WsusSamples
{
  using System;
  using System.Xml;

  using Microsoft.UpdateServices.Administration;

  class DetermineUpdateStatusForAllComputers
  {
    static void Main(string[] args)
    {
      const string usage = "\r\n" +
                            "ComputerStatusToXml. Creates an XML file with a list computers on the Update Services server, " +
                            "and the status of updates approved for each computer." +
                            "\r\n\r\n" +
                            "USAGE:" +
                            "\r\n\r\n" +
                            "    ComputerStatusToXml.exe [IncludeDownstreamComputers]" +
                            "\r\n\r\n" +
                            "        IncludeDownstreamComputers: Include computer targets rolled up from downstream servers." +
                            "\r\n";

      // evaluate args
      bool includeDownstreamComputers = false;
      if (args.Length >= 1)
      {
        if (args.Length > 1 || args[0].ToLower() != "includedownstreamcomputers")
        {
          Console.WriteLine(usage);
          return;
        }
        if (args[0].ToLower() == "includedownstreamcomputers")
        {
          includeDownstreamComputers = true;
        }
      }

      XmlTextWriter xml = null;

      try
      {
        Console.WriteLine("Getting computer status...");

        // open the XML file
        string xmlWriterFile = string.Format("{0}{1}{2}{3}",
                                              Environment.CurrentDirectory.ToString(),
                                              "\\ComputerStatus ",
                                              DateTime.Now.ToLongDateString().ToString(),
                                              ".xml");
        xml = new XmlTextWriter(xmlWriterFile, System.Text.Encoding.UTF8);
        xml.Formatting = Formatting.Indented;
        xml.Indentation = 4;

        xml.WriteStartDocument(true);
        xml.WriteStartElement("ComputerStatus");


        // Connect to the local WSUS server
        IUpdateServer updateServer = AdminProxy.GetUpdateServer();

        // Get the collection of computers on this server
        ComputerTargetScope computerTargetScope = new ComputerTargetScope();
        computerTargetScope.IncludeDownstreamComputerTargets = includeDownstreamComputers;
        ComputerTargetCollection computers = updateServer.GetComputerTargets(computerTargetScope);

        // loop through the computer collection 
        foreach (IComputerTarget computer in computers)
        {
          // start the element for the computer
          xml.WriteStartElement("Computer");
          xml.WriteAttributeString("Name", computer.FullDomainName);

          xml.WriteAttributeString("LastReportedStatus", computer.LastReportedStatusTime.ToString());

          if (includeDownstreamComputers == true)
          {
            string parentName = "LocalHost";
            if (computer.ParentServerId != Guid.Empty)
            {
              parentName = computer.GetParentServer().FullDomainName;
            }
            xml.WriteAttributeString("ParentServer", parentName);
          }

          // start the element for the status of updates on this computer
          xml.WriteStartElement("UpdateStatus");

          // get the install state of all updates approved for this computer
          UpdateInstallationInfoCollection installStatus = computer.GetUpdateInstallationInfoPerUpdate();

          // loop through the updates in the install info collection and output the 
          // name of the update and it's install state on this computer
          foreach (IUpdateInstallationInfo updateStatus in installStatus)
          {
            xml.WriteStartElement("Update");
            xml.WriteAttributeString("Title", updateStatus.GetUpdate().Title);
            xml.WriteAttributeString("Status", updateStatus.UpdateInstallationState.ToString());

            // close the Update element
            xml.WriteEndElement();
          }

          // close the UpdateStatus element
          xml.WriteEndElement();

          // close the Computer element
          xml.WriteEndElement();
        } // foreach

      } //try
      catch (Exception)
      {
      } // catch
      finally
      {
        Console.WriteLine("Done. Results are written to the ComputerStatus {0}.xml file in the current folder",
                          DateTime.Now.ToLongDateString());
        xml.Close();
      } // finally
    } // main
  }
}

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Community Additions

ADD
Show: