简体   繁体   中英

How to run array of Invoke-SshCommand in PowerShell script?

I would like to run a couple of SSH commands using PowerShell Invoke-SshCommand . I know how to use it, but when I want to run more of them like for example sudo apt-get update , sudo apt-get install and cd.. they do not wait for each other and it causes errors. Is there any way of getting the information whether one command was finished so I could run next?

Don't invoke the commands separately. Daisy-chain the commands with semicolons and invoke the entire list in a single statement:

$cmds = 'sudo apt-get update', 'sudo apt-get install', 'cd ..'
Invoke-SshCommand -Command ($cmds -join ';')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM