What's the easiest way to batch SSH into multiple devices and run commands?

March 22, 2026 5 answers
Asked by TechieNinja42
I'm trying to automate SSH access to around 100 brand new devices on my local network. I need to connect, accept the host key (security isn't a concern here), issue a command, and then move on to the next device. I've got their IP addresses in a CSV file. The traditional methods I've tried, like using PLINK, haven't worked outโ€”particularly piping 'yes' to it just hangs. I'm looking for a PowerShell script that can do this efficiently without the hassle of logging in manually to each device. Any suggestions?

Answers

CodeGuru88
You might want to try using SSH with the option `-o StrictHostKeyChecking=accept-new` or `-o StrictHostKeyChecking=no`. This should help you bypass the host key checks and let you connect without issues.

ScriptingWizard007: This is a good call! Honestly, forget about PuTTY and PLINK; theyโ€™re pretty outdated at this point.

Reply to this answer
DevOpsDweller
Consider using threads or jobs to run your connections in parallel. This could speed things up significantly!
Reply to this answer
PowerShellPal
Just remember, you donโ€™t actually need to log in to get the key. You can connect and pipe in `echo y` to accept the key. Check your loop structure to make sure it isnโ€™t hangingโ€”try running something like `echo y | plink -ssh user@device "exit";`

CodeMaster101: I tried both methods in a loop, and they still just hang. Itโ€™s so frustrating!

Reply to this answer
NetworkingPro
Keep in mind that PLINK has a `-batch` option you can use. It might be the solution you need to avoid those annoying prompts.
Reply to this answer
TheCloudinator
Have you looked into using Posh-SSH? It might streamline the process for you.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions