WinRM
D.device.sendWinRMCommand runs a single command against a Windows host over HTTP(S) WinRM. Use this for anything PowerShell can read — service state, performance counters, registry keys, WMI queries.
Quick shape
Section titled “Quick shape”D.device.sendWinRMCommand({ command: 'Get-CimInstance Win32_OperatingSystem | Select-Object -Property Caption, LastBootUpTime | ConvertTo-Json', username: 'admin', password: 'secret'}, function (output, error) { if (error) return D.failure(D.errorType.RESOURCE_UNAVAILABLE); var data = JSON.parse(output); var up = D.createVariable('os', 'OS', data.Caption, '', D.valueType.STRING); D.success([up]);});The callback is (output, error). output is the command’s stdout. Pipe through ConvertTo-Json on the Windows side whenever you can — JSON is easier to parse than free-form text.
Options
Section titled “Options”D.device.sendWinRMCommand({ command: '...', username: 'admin', password: 'secret', port: 5985, protocol: 'http', timeout: 10000, shell: 'powershell'});Default port is 5985 (HTTP). Switch to 5986 + protocol: 'https' whenever the device supports it — credentials are NTLM-encrypted on HTTP, but HTTPS is strongly preferred.
Authentication
Section titled “Authentication”Default: uses the Custom Driver Management credentials configured in the Domotz portal (D.device.username() / D.device.password()).
Per-call override: pass username / password. Domain accounts use DOMAIN\user or user@domain.tld.
Kerberos is not currently exposed to custom drivers — NTLM is the default.
PowerShell patterns
Section titled “PowerShell patterns”Return JSON
Section titled “Return JSON”Get-Service -Name 'wuauserv' | Select-Object Name, Status | ConvertTo-JsonThen in JS: var data = JSON.parse(output);
Return a single number
Section titled “Return a single number”(Get-Counter '\\Processor(_Total)\\% Processor Time').CounterSamples.CookedValueParse with parseFloat(output.trim()).
Run a CIM query for WMI-style data
Section titled “Run a CIM query for WMI-style data”Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" | Select-Object DeviceID, @{n='FreeGB'; e={[math]::Round($_.FreeSpace/1GB, 2)}} | ConvertTo-Json -CompressError handling
Section titled “Error handling”D.device.sendWinRMCommand({ command: '...' }, function (output, error) { if (error) { if (error.code === 'AUTHENTICATION_FAILED') return D.failure(D.errorType.AUTHENTICATION_ERROR); if (error.code === 'TIMEOUT_ERROR') return D.failure(D.errorType.TIMEOUT_ERROR); return D.failure(D.errorType.RESOURCE_UNAVAILABLE); } try { var data = JSON.parse(output); // ... } catch (e) { return D.failure(D.errorType.PARSING_ERROR); }});