Skip to content

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.

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.

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.

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.

Terminal window
Get-Service -Name 'wuauserv' | Select-Object Name, Status | ConvertTo-Json

Then in JS: var data = JSON.parse(output);

Terminal window
(Get-Counter '\\Processor(_Total)\\% Processor Time').CounterSamples.CookedValue

Parse with parseFloat(output.trim()).

Terminal window
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
Select-Object DeviceID, @{n='FreeGB'; e={[math]::Round($_.FreeSpace/1GB, 2)}} |
ConvertTo-Json -Compress
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);
}
});