Run commands on Windows from Linux NodeRed

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?

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" ?

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.

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

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.

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

Best regards, Walter

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.

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

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

2 Likes

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.

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.

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.

Hi there, This is a little bit of older post but I am wondering if you could perhaps help me.

I am having trouble where my node red instance on my main server would for whatever reason
stop capturing data or doing anything for that matter. only solution is to log in and restart.
Now I had created a "Heartbeat" system between 2 of my node red systems to alert if there
are any issues with either one of them. Trouble is I am now trying to get either one to restart
their partners node red instance. One is a linux system and the other is a windows base.
I would really like to use ssh to run a command on the partner system to restart the node red instance.

Do you know perhaps how to do that? id read the post above and it isnt exactly fitting to the problem I have.

thank you

If this thread doesn't help, I recommend starting a new one so that it gets better visibility.

Thanks and will do. I sort of managed to figure out telegram and node red but I am far from being able to apply better uses for it. I know this is neither here nor there lol. but I will ask the question in the forum.

thanks