Pages

3/25/2016

powershell ssh

One method for using powershell to ssh to a router/etc:
powershelladmin


Unfortunately it doesn't accept a credential object.
One workaround would be something like the following pseudo code:




import-module ssh-sessions
$cred = get-credential
$user = $cred.getnetworkcredential().username
$pw = $cred.getnetworkcredential().password
(create log file)
(get $list of hosts from file)
(get $commands from file)
(for each $comp in $list)
 (output $comp to log file)
 $loginresult = new-sshsession $comp -username $user -password $pw
 (output $loginresult to log file)
 (for each $cmd in $commands)
  $sshresults = invoke-sshcommand -computername $host -command $cmd
  (output $sshresults to log file)
  }
 $logoutresult = remove-sshsession -computername $comp
 (output $logoutresult to log file)
 }

No comments: