Session.Enumerate method

Enumerates a table, data collection, or log resource. To create a query, include a filter parameter and a dialect parameter in an enumeration. You can also use a ResourceLocator object to create queries. For more information, see Enumerating or Listing All of the Instances of a Resource.

Syntax

Session.Enumerate( _
  ByVal resourceUri, _
  [ ByVal filter ], _
  [ ByVal dialect ], _
  [ ByVal flags ] _
)

Parameters

resourceUri [in]

The identifier of the resource to be retrieved.

This parameter can contain one of the following:

filter [in, optional]

A filter that defines what items in the resource are returned by the enumeration. When the resource is enumerated, only those items that match the filter criteria are returned. Including a filter parameter and a dialect parameter in an enumeration converts the enumeration into a query. For an example, see Querying for Specific Instances of a Resource.

If you have a ResourceLocator object for the resourceURI parameter, then this parameter should not be used.

dialect [in, optional]

The language used by the filter. WQL, a subset of SQL used by WMI, is the only language supported.

If you have a ResourceLocator object for the resourceURI parameter, then this parameter should not be used.

flags [in, optional]

A parameter that must contain a flag in the __WSManEnumFlags enumeration. For more information, see Enumeration Constants.

Return value

An Enumerator object that contains the results of the enumeration.

Remarks

For more information about limiting network calls during an enumeration, see the BatchItems property.

Be aware that if the flags include the Enumeration Constants WSManFlagHierarchyDeepBasePropsOnly or WSManFlagHierarchyShallow then Windows Remote Management service returns the error code ERROR_WSMAN_POLYMORPHISM_MODE_UNSUPPORTED.

If a filter is specified, it must be a valid document with respect to the schema of the resource. The dialect parameter is optional. However, if the filter string begins with <, but is not an XML fragment, then either include the dialect parameter or set the WSManFlagNonXmlText flag in the flags parameter. For more information, see Enumeration Constants.

The corresponding C++ method is IWSManSession::Enumerate.

Examples

The following VBScript code example enumerates the Win32_LogicalDisk instances on a remote computer specified by the fully qualified domain name (servername.domain.com). Be aware that freeing the enumeration object clears pending enumeration requests. The DisplayOutput subroutine uses the Winrm command-line tool XML transform file (WsmTxt.xsl) to output the data in a tabular form.

Const RemoteComputer = "servername.domain.com"
Set objWsman = CreateObject( "WSMan.Automation" )

Set objSession = objWsman.CreateSession( "https://" & REMOTECOMPUTER )

strResource = "http://schemas.microsoft.com/wbem/wsman/1/" &_
              "wmi/root/cimv2/Win32_LogicalDisk"

Set objResultSet = objSession.Enumerate( strResource )

While Not objResultSet.AtEndOfStream
 
 DisplayOutput( objResultSet.ReadItem ) 

Wend

'****************************************************
' Displays WinRM XML message using built-in XSL
'****************************************************
Sub DisplayOutput( strWinRMXml )
    Dim xmlFile, xslFile
    Set xmlFile = CreateObject( "MSXml2.DOMDocument.3.0" ) 
    Set xslFile = CreateObject( "MSXml2.DOMDocument.3.0" )
    xmlFile.LoadXml( strWinRMXml )
    xslFile.Load( "WsmTxt.xsl" )
    Wscript.Echo xmlFile.TransformNode( xslFile ) 
End Sub

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Header
WSManDisp.h
IDL
WSManDisp.idl
Library
WSManDisp.tlb
DLL
WSMAuto.dll

See also

Session

Querying for Specific Instances of a Resource

BatchItems

ResourceLocator