Set remote time via WMI (invoke Win32_OperatingSystem.SetDateTime())

0

The goal is to make XML/SOAP/WSMan request from Python and Linux and set time on remote Windows 10 machine.

I can do that via CMD, PowerShell or Cygwin/SSH but I need fast native way. I'm doing a lot via WMI, it's simpler and faster.

I try to invoke Win32_OperatingSystem.SetDateTime.
SOAP/WSMan response conatains: The SOAP XML in the message does not match the corresponding XML schema definition. Change the XML and retry. (extended fault data: {u'fault_subcode': 'w:SchemaValidationError', u'fault_code': 's:Sender', u'wsmanfault_code': '2150858817', 'transport_message': u'Bad HTTP response returned from server. Code 500', 'http_status_code': 500})

I tried to accomplish similar task manually on both local and remote machines. Results are same.

Via WMIC:

C:\Users\Administrator>wmic /node:10.254.251.2 os call SetDateTime 20180517141043.945000+000
Executing (Win32_OperatingSystem)->SetDateTime()
ERROR:
Description = Invalid method Parameter(s)

Via WinRM:

C:\Users\Administrator>winrm invoke SetDateTime wmicimv2/Win32_OperatingSystem @{LocalDateTime="20170505080808.123123+120"}
WSManFault
    Message
        ProviderFault
            WSManFault
                Message = The WS-Management service cannot process the request. The element for a datetime value must have exactly one child and no mixed content.

Error number:  -2144108479 0x80338041
The SOAP XML in the message does not match the corresponding XML schema definition. Change the XML and retry.

Via PowerShell's WMI cmdlets:

PS C:\Users\Administrator> Invoke-WmiMethod -Class Win32_OperatingSystem -Name SetDateTime -ArgumentList '20180517133310.323710+000' -ComputerName 10.254.251.2
Invoke-WmiMethod : Invalid method Parameter(s) 
At line:1 char:1
+ Invoke-WmiMethod -Class Win32_OperatingSystem -Name SetDateTime -Argu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-WmiMethod], ManagementException
    + FullyQualifiedErrorId : InvokeWMIManagementException,Microsoft.PowerShell.Commands.InvokeWmiMethod

If I change string format, I get Type Error. Only with this format, which seems to be correct, I get Invalid method Parameter(s).

Also I get Invalid method Parameter(s) when executing from WBEMTest.

I explored method types with WBEMTest. Parameter type is CIM_DATETIME. What's wrong with it? How do I change time on remote machine?

How do I set time via WMI?

What's the "corresponding schema definition" and how do I obtain it?

George Sovetov

Posted 2018-05-17T14:42:41.383

Reputation: 157

Answers

1

Via WMIC: I'm noob in wmic using, but I found the command with kinda of filtering like that:

wmic os where(primary=1) call setdatetime 20070731144642.555555+480

I've checked and it really works. So, I think it should be the same with the remote calling using /node. I hope it will be useful for you.

Here the source of the code: link

Vitali Kuzniatsou

Posted 2018-05-17T14:42:41.383

Reputation: 11

Apparently, two differences are /node argument and where(1) clause. When I get back to this project, I'll definitely check both. Thanks. – George Sovetov – 2018-07-28T16:33:28.803

0

I couldn't make it work with wmic but this XML works for me:

<?xml version="1.0" ?>
<env:Envelope xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:b="http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd" xmlns:cfg="http://schemas.microsoft.com/wbem/wsman/1/config" xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:n="http://schemas.xmlsoap.org/ws/2004/09/enumeration" xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd" xmlns:rsp="http://schemas.microsoft.com/wbem/wsman/1/windows/shell" xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:x="http://schemas.xmlsoap.org/ws/2004/09/transfer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <env:Header>
    <w:OperationTimeout>PT00H02M00.000S</w:OperationTimeout>
    <a:To>http://windows-host:5985/wsman</a:To>
    <w:SelectorSet/>
    <w:MaxEnvelopeSize mustUnderstand="true">153600</w:MaxEnvelopeSize>
    <w:ResourceURI mustUnderstand="true">http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_OperatingSystem</w:ResourceURI>
    <a:Action mustUnderstand="true">http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_OperatingSystem/SetDateTime</a:Action>
    <p:DataLocale mustUnderstand="false" xml:lang="en-US"/>
    <a:ReplyTo>
      <a:Address mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
    </a:ReplyTo>
    <a:MessageID>uuid:52029873-fef3-4f08-ba32-57827df5fb2c</a:MessageID>
    <w:Locale mustUnderstand="false" xml:lang="en-US"/>
  </env:Header>
  <env:Body>
    <SetDateTime_INPUT xmlns:cim="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_OperatingSystem" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <p:LocalDateTime>
        <cim:Datetime>2018-07-21T19:51:34.365502Z</cim:Datetime>
      </p:LocalDateTime>
    </SetDateTime_INPUT>
  </env:Body>
</env:Envelope>

This is the same format WMI responds with when getting Win32_OperatingSystem, for example.

George Sovetov

Posted 2018-05-17T14:42:41.383

Reputation: 157