forked from shoneslab/nodejs-winrm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
44 lines (36 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
let shell = require('./src/shell.js');
let command = require('./src/command.js');
module.exports = {
shell: shell,
command: command
};
module.exports.runCommand = async function (_command, _host, _username, _password, _port, _usePowershell = false) {
try {
var auth = 'Basic ' + Buffer.from(_username + ':' + _password, 'utf8').toString('base64');
var params = {
host: _host,
port: _port,
path: '/wsman',
};
params['auth'] = auth;
var shellId = await shell.doCreateShell(params);
params['shellId'] = shellId;
params['command'] = _command;
var commandId
if ( _usePowershell ) {
commandId = await command.doExecutePowershell(params);
} else {
commandId = await command.doExecuteCommand(params);
}
params['commandId'] = commandId;
var output = await command.doReceiveOutput(params);
await shell.doDeleteShell(params);
return output;
} catch (error) {
console.log('error', error);
return error;
}
};
module.exports.runPowershell = async function (_command, _host, _username, _password, _port) {
return module.exports.runCommand(_command, _host, _username, _password, _port, true);
}