Run commands on Windows from Linux NodeRed


#1

I've got Node Red running on a Pi3. I use it to do some scheduling of operations on various Linux VMs and other Pis, this all works fine with the exec node and passwordless SSH. However I also want to run some operations on a few Windows VMs and I can't see an integrated way to do this, I've certainly not found a Windows Exec node.

I've had a couple of ideas -

  1. Make a share on the Windows machines and mount it on the Pi, write a flag file into it. The Windows machines poll for the file, when it's there, kick off a process. Not nice, tedious to setup, relies on polling, no feedback to Node-Red.

  2. Have an MQTT client on the Windows machines, when an appropriate message is obtained, run a pre-determined command. Return exit code in another MQTT message. No polling, will run immediately, but hard to marry up the outgoing and return messages.

Does anyone have any ideas as to how running commands on Windows machines may be achieved and how to get exit codes returned to node red?


#2

the exec node should exist on windows as well - nothing very special about it afaik. Or is what you're asking "how to enable ssh into a windows box" ?


#3

Alternative 1), no thanks, that feels like old stone age, at least back in the 80's, I think :wink: Easiest I assume, would be to follow the advice given by @dceejay, exchanging messages between Node-RED's via MQTT

If you feel comfortable with sw coding, Python in this case, you could look into this simple but very effective sample (TCP Client Server)
https://wiki.python.org/moin/TcpCommunication

You could have the TCP server running in your Windows machine and use TCP in Node-RED in your Pi3. In Python you can then easily execute suitable commands in your Windows box. But exactly "how-to" is half-way OT I suppose, at least only half-way Node-RED.


#4

no need for python - Node-RED can do TCP if you wanted to :wink:


#5

If it's an option, I'd definitely go for installing node-red on the machine to be controlled and use mqtt or a tcp connection between instances to relay the commands. (Probably a good lazy option if you're comfortable installing NR on windows.)

Another option to consider is to install powershell 6 on your machines and have an exec node on the pi invoke powershell to then use powershell remote to issue commands on the remote machine.


#6

NR <-> TCP ----- TCP <-> NR
Right, of course, I did that myself once, what was I thinking of? So many possibilities...

Best regards, Walter


#7

Thanks for your suggestions.
I think I'm erring towards using a MQTT agent on the target server to receive commands to run, then wait to receive a reply.

I'm reluctant to use a full install of NR on a server which isn't primarily NR, this seems a bit heavyweight a solution. I am though looking at running SSH server on Windows, which seems like it's in beta at the moment, however this doesn't cover my servers which are older than 2016/Win10.


#8

Just did a quick test. About 80MB of memory and not enough CPU utilization to actually register in my logs.


#9

I use NR on one of my servers as a task scheduler. It was much easier than using the native scheduler on Windows. I run NR as a service using NSSM. The NSSM setup was easy with the help of this link by @dceejay

https://gist.github.com/dceejay/576b4847f0a17dc066db


#10

Using the exec node, you can run PowerShell scripts. PS lets you run remote scripts assuming the server allows it and you have the correct authentication and authorisation.

I've toyed previously with the idea of building a node around EdgeJS which lets you call out to .net, PS and others directly but I've not yet had enough of a driver to actually get round to it.


#11

I've toyed previously with the idea of building a node around EdgeJS.

If you ever decide to do this, I'd be very interested in it. I've been playing around with the Edge-js NPM module lately in a function node. Having its own node would be very cool as it would add a lot more flexibility to NR.


#12

OK, I'll keep it on my backlog. Not really any spare time to take on another personal project at the moment.

Also, needs some thought as to requirements.

In the meantime, you might want to look at one of the contributed function nodes that allows you to have require'd modules. If you get a chance to play, let me know what works and what doesn't.