Enumerator.ReadItem method

Retrieves an item from the resource and returns an XML representation of the item.

Syntax

Enumerator.ReadItem( _
  ByVal resource _
)

Parameters

resource

The URI of the item.

Return value

The XML representation of the item.

Remarks

To limit the number of items that are read, set the Session.BatchItems property.

Note that the freeing of the enumeration object cleans up any pending enumeration requests.

The Session.Enumerate method does not obtain a collection in the same way that a WMI query, such as SELECT * from Win32_LogicalDisk, returns a collection in an SWbemObjectSet. To read a file as a text stream, you create the scripting TextStream object and call the TextStream.Readline method to read each line of the file. In a similar way, you call the Session.Enumerate method to obtain an Enumerator object and then call the Enumerator.ReadItem method. As in reading from the text file, you can check the Enumerator.AtEndOfStream property to check for whether you have reached the end of the data items.

Examples

The following VBScript example calls the Session.Enumerate method to obtain a list of scheduled jobs. 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_ScheduledJob"

Set objResultSet = objSession.Enumerate( strResource )
NumOfJobs = 0

While Not objResultSet.AtEndOfStream
    NumOfJobs = NumOfJobs + 1
    DisplayOutput( objResultSet.ReadItem ) 
Wend

Wscript.Echo "There are " & NumOfJobs & " jobs scheduled."

'****************************************************
' 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

Enumerator

Enumerating or Listing All the Instances of a Resource