I'm looking for a simple PowerShell script that lets me SSH into a list of devices and execute a command automatically. The devices are all new and on a local network, and I don't care about the host key since it will change after I finish this initial task. I just want to accept the host key the first time, run a command, and then move on to the next device. I've got a CSV file with all the IPs listed. When I try to pipe 'y' to PLINK, it just hangs and does nothing. I need a straightforward solution to do this for 100 devices without manually connecting to each one. Is there an easy way to achieve this?
5 Answers
Honestly, putty and plink are pretty dated. If you are set on scripting, why not use native SSH commands or tools instead? That could simplify your life a lot!
You can try using the `-o StrictHostKeyChecking=accept-new` option with SSH to automatically accept host keys. Alternatively, using `-o StrictHostKeyChecking=no` will also skip the prompt entirely, which should help you get through your list without any hang-ups.
Consider using threads or jobs for the connections if you're facing timeouts or slowdowns. Parallelizing your script can significantly speed up the process of handling multiple devices.
I think you're overcomplicating it a bit. You don’t actually need to log in first to accept the key; just connect. Try this in your PowerShell script: `echo y | plink -ssh user@device "exit"`. That should get you where you need to go without the hang-ups you're experiencing.
Have you considered using Posh-SSH? It's a PowerShell module that simplifies SSH connections and could work better for your case. It allows you to handle the host keys more flexibly. Plus, instead of PLINK, it integrates more smoothly with PowerShell scripting.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically