Export (0) Print
Expand All

Session.Get method

Retrieves the resource specified by the URI and returns an XML representation of the current instance of the resource.

Syntax


resource = .Get( _
  ByVal resourceUri, _
  [ ByVal flags ] _
)

Parameters

resourceUri [in]

The identifier of the resource to be retrieved.

This parameter can contain one of the following:

  • A URI with or without selectors. When calling the Get method with a selector to obtain a WMI resource, use the key property or properties of the object. For example, in the following Visual Basic Scripting Edition (VBScript) code example, the key is specified by Win32_Service?Name=winmgmt. For singleton classes, such as Win32_LocalTime, you cannot use a selector.
    
    strResourceUri = "http://schemas.microsoft.com/" _ 
        & "wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt"
    
    strResourceUri = "http://schemas.microsoft.com/" _ 
        & "wbem/wsman/1/wmi/root/cimv2/Win32_LocalTime"
    
    
  • A ResourceLocator object which may contain selectors, fragments, or options.
  • A WS-Addressing endpoint reference as described in the WS-Management protocol standard. For more information about the public specification for WS-Management protocol, see Management Specifications Index Page.
flags [in, optional]

Reserved. Must be set to 0.

Return value

A value that, upon success, is an XML representation of the resource.

Examples

The following VBScript code example retrieves the XML representation of the Win32_Service instance that represents the WMI Winmgmt service on the local computer.




'Create a WSMan object.
Set objWsman = CreateObject( "WSMAN.Automation" )
If objWsman is Nothing Then
    WScript.Echo "Failed to create WSMAN Automation object"
    WScript.Quit
End If 

'Create a Session object.
Set objSession = objWsman.CreateSession
If objSession is Nothing Then
    WScript.Echo "Failed to create WSMAN Session object"
    WScript.Quit
End If 


strResourceUri = "http://schemas.microsoft.com/" _ 
    & "wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt"

On Error Resume Next
xmlResource = objSession.Get( strResourceUri )
WScript.Echo "Response message: " & Chr(10) & xmlResource
If Err.Number <> 0 Then
    DisplayErrorInfo
End If
On Error Goto 0

Sub DisplayErrorInfo()
    WScript.Echo "An error has occurred."     
    WScript.Echo
    WScript.Echo "Error Info"
    WScript.Echo "-----------"
    WScript.Echo "Number      : 0x" & hex(Err.number)
    WScript.Echo "Description : " & Err.Description
    WScript.Echo "Source      : " & Err.Source
    WScript.Echo "HelpFile    : " & Err.helpfile
    WScript.Echo "HelpContext : " & Err.HelpContext    
    WScript.Echo Err.Clear    
End Sub



The following VBScript code example retrieves the WMI Winmgmt service instance from a remote computer. The remote computer is identified by the fully qualified domain name (servername.domain.com). The only difference between the local and remote version is the specification of the remote computer in the call to WSMan.CreateSession.



Const RemoteComputer = "servername.domain.com"

'Create a WSMan object.
Set objWsman = CreateObject( "WSMAN.Automation" )
If objWsman is Nothing Then
    WScript.Echo "Failed to create WSMAN Automation object"
    WScript.Quit
End If 

'Create a Session object.
Dim objSession
Set objSession = objWsman.CreateSession( "http://" & RemoteComputer )
If objSession is Nothing Then
    WScript.Echo "Failed to create WSMAN Session object"
    WScript.Quit
End If 


strResourceUri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" _ 
    & "Win32_Service?Name=winmgmt"


On Error Resume Next
xmlResource = objSession.Get( strResourceUri )
WScript.Echo "Response message: " & Chr(10) & xmlResource
If Err.Number <> 0 Then
    DisplayErrorInfo
End If
On Error Goto 0

Sub DisplayErrorInfo()
    WScript.Echo "An error has occurred."     
    WScript.Echo
    WScript.Echo "Error Info"
    WScript.Echo "-----------"
    WScript.Echo "Number      : 0x" & hex(Err.number)
    WScript.Echo "Description : " & Err.Description
    WScript.Echo "Source      : " & Err.Source
    WScript.Echo "HelpFile    : " & Err.helpfile
    WScript.Echo "HelpContext : " & Err.HelpContext    
    WScript.Echo Err.Clear    
End Sub


Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Redistributable

WinRM 1.1 (Windows Server 2003 R2, or Windows Server 2003 with SP1)

Header

Wsmandisp.h

IDL

Wsmandisp.idl

Library

WSManAutomation.lib

DLL

Wsmauto.dll

See also

Session

 

 

Show:
© 2015 Microsoft