Windows Remote Management and WMI
Windows Remote Management can be used to retrieve data exposed by Windows Management Instrumentation (WMI). You can obtain WMI data with scripts or applications that use the WinRM Scripting API or through the Winrm command-line tool.
WinRM supports most of the familiar WMI classes and operations, including embedded objects. WinRM can leverage WMI to collect data about resources or to manage resources on a Windows-based operating system. That means that you can obtain data about objects such as disks, network adapters, services, or processes in your enterprise through the existing set of WMI classes. You can also access the hardware data that is available from the standard WMI IPMI provider.
Windows Server 2003 with SP1, Windows Server 2003, Windows XP, and Windows 2000: You cannot obtain WMI data through WinRM because the service is not available.
You can reference a WMI class as a resource in WinRM and in the WS-Management protocol: a type of managed entity, like a service or a disk.
A WMI class or method is identified by a URI, just as any other resource is when using the WS-Management protocol. The URI can specify a WMI resource (class), a WMI action (method), or identify a specific instance of a class in messages sent over a network. For more information, see Resource URIs.
The URI prefix contains a fixed part and the WMI namespace. For example, the URI prefix in Windows Server 2003 R2 that contains the fixed part of the prefix is: http://schemas.microsoft.com/wbem/wsman/1/wmi/<WmiNamespace>. This allows the URI prefix to be generated for any WMI namespace. For example, to access the root\default WMI namespace, use the following URI prefix: http://schemas.microsoft.com/wbem/wsman/1/wmi/root/default/.
The majority of the WMI classes for management are in the root\cimv2 namespace. To access classes and instances in root\cimv2 namespace, use the URI prefix: http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/. For more information, see Resource URIs.
The URI that you supply, either to the Winrm command-line tool or to a script, consists of the prefix plus the resource specification.
The following procedure describes how to generate a resource URI either to get a WMI class or to use in an enumerate operation.
To generate a resource URI for a WMI class
- Start with the prefix that indicates the WS-Management protocol schema should be used.
The resource URI prefix for WMI classes is always the same. For more information, see URI Prefixes.
- Add the WMI namespace to the prefix.
- Add the class name.
- To set the value of a property, or to invoke a specific method, add the required key value or values for the class.
If you leave the key value blank, you will not alter the original property value.
Windows 7: Leaving the key value blank sets the property value to NULL.
You can obtain WMI data either through the command-line tool, Winrm, or through a Visual Basic script that uses the WinRM Scripting API. You do not use a WMI path to locate a resource. Instead, you convert the WMI namespace and hierarchy to a URI.
The WinRM URI for a WMI class contains two parts: the URI prefix and the class that you want to access.
For example, the following URI can be supplied to the Session.Enumerate method to list all the services on a computer. The URI prefix is http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/ and the class is Win32_Service.
strResourceUri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_CurrentTime"
In WMI, list the data for all of the instances of a resource or class in several ways:
A query for all the instances of that resource.
Set colServices = objWMIService.ExecQuery("Select * from Win32_Service")
Set colServices = InstancesOf("Win32_Service")
In WinRM, there is one way to list all of the instances of a resource: Session.Enumerate.
strResource = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service" Set colServices = objSession.Enumerate( strResource )
In WMI, you can designate a particular instance of a class either by specifying values for the key properties or by querying for an instance that matches a list of property values. Key properties have the WMI Key qualifier.
You can obtain a specific instance of a class in several ways:
- A call to Session.Enumerate with the filter and dialect parameters to create a query.
RemoteComputer = "servername.domain.com" strDialect = "http://schemas.microsoft.com/wbem/wsman/1/WQL" strResource = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*" Set objWsman = CreateObject("Wsman.Automation") Set objSession = objWsman.CreateSession("http://" & RemoteComputer) strFilter = "SELECT * FROM Win32_Share WHERE Name='Admin$'" Set objResultSet = objSession.Enumerate(strResource, strFilter, strDialect)
- A call to SWbemServices.Get. For Session.Get, you must supply one or more specific key values, preceded by a question mark (?).
The format of the URI for a specific instance is http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/WMI_Class?Key1=Value.
strResourceUri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt"
A WMI class may have more than one key. Key name-value pairs are separated by a "+" sign. In that case, the format is: http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Key1=Value1+Key2=Value2.
The WinRM syntax to obtain a singleton WMI object is different from WMI. A singleton is a WMI class defined so that only one instance is allowed. Win32_CurrentTime or Win32_WMISetting are examples of a WMI singleton class.
The WMI syntax for singletons is shown in the following VBScript code example.
The following example shows the WinRM singleton syntax which does not use "@".
- Adding a selector to a ResourceLocator or IWSManResourceLocator object.
The following VBScript code example shows how to use a selector to get a specific instance of Win32_Processor.
Build date: 10/15/2013