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