1

I am pretty new to using PowerShell for automation. I want to ssh into a machine, and run a git pull in it. This works when I do it through the powershell manually, but not when I automate it through the code. What I have is:

$Password = "mypsw"
$User = "myusername"
$ComputerName = "computername"

$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential($User, $secpasswd)

$SessionID = New-SSHSession -ComputerName $ComputerName -Credential $Credentials 

#$result = Invoke-SSHCommand -Index $sessionid.sessionid -Command "ls"
$result.Output # this one works as expected, returns the list of folders and files
$result = Invoke-SSHCommand -Index $sessionid.sessionid -Command "git pull"
$result.Output # this doesn't return anything

If I don't save the $result value, I get

Host       : [myhost]
Output     : {}
ExitStatus : 128

which is pointing to an error message. However I will never be able to debug it if I don't know exactly what the output of the console is. So I guess I have two problems here.

1) How to get the real output of the remote console in my shell

2) How to make git pull work

And a general question:

Is PowerShell the right tool for automating these tasks, or should I use something different? Thanks

Citizen
  • 1,103
  • 1
  • 10
  • 19
user2116599
  • 111
  • 2
  • I would recommend having your script send all of its output to a log file. Then you should be able to see the exact error messages in the log. – TTT Apr 21 '20 at 18:32
  • I have done everything using putty and plink. No reason to complicate my life :) – user2116599 Apr 21 '20 at 19:34

0 Answers0