Export (0) Print
Expand All

Session.Create method

Creates a new instance of a resource and returns the endpoint reference (EPR) of the new object.

Syntax

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

Parameters

resourceUri [in]

Identifier of the resource to create.

This parameter can contain one of the following:

resource

The XML that contains resource content.

flags [in, optional]

Reserved. Must be set to 0.

Return value

The EPR of the new resource.

Remarks

Session.Create is only used for creating new instances of a resource. Use the Session.Put method to update existing instances of a resource. After you obtain the new resource URI, you can call Session.Get to retrieve the new object. The new object contains any properties that the resource provider assigns when creating the new object. For example, if you create a new WS-Management protocol listener and retrieve the listener object using Session.Get, then you also obtain the Port, Enabled, and ListeningOn properties.

Be aware that the WMI plug-in does not support creating any resource other than a WS-Management protocol listener.

The following syntax is used to call this method.

uri = session.Create("<resourceUri>", "<resource>")

Examples

The following VBScript code example calls Session.Create to create a listener on the local computer.

'Create a WSMan object
Set oWsman = CreateObject( "WSMAN.Automation" )

'Create a Session object
Set oSession = oWsman.CreateSession

'Define resourceUri and inputXml 
resourceUri = "http://schemas.microsoft.com/wbem/wsman/1/"_
    & "config/Listener?Address=*+Transport=HTTP"

inputXml = _
    "<cfg:Listener xmlns:cfg=""http://schemas.dmtf.org/wbem/wsman/1/"_
    & "config/Listener.xsd"">" _
    & "<cfg:Hostname>" & GetFQDNName() & "</cfg:Hostname>" _            
    & "</cfg:Listener>"

'Perform the create operation.
response = oSession.Create( resourceUri, inputXml )
WScript.Echo "Response message: " & Chr(10) & response

Function GetFQDNName()
    Dim oShell, userDNSDomain, localComputerName
    Set oShell = CreateObject("WScript.Shell")
    userDNSDomain = oShell.ExpandEnvironmentStrings("%USERDNSDOMAIN%")

    localComputerName = _
        oShell.ExpandEnvironmentStrings("%ComputerName%")
    If userDNSDomain = "%USERDNSDOMAIN%" Then
        GetFQDNName= localComputerName
    Else
        GetFQDNName= localComputerName & "." & userDNSDomain
    End If
End Function

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:
© 2014 Microsoft