invoke-sshcommand trying to see output - save output

Basically I am writing a script to clear the SEL logs on ESXi. I am trying to save output to a variable and be able to see that something actually did happen on the host. I have tried a few variations on what I have below but I am stumped. Just trying something simple like changing directories and output where I am at in the script. I SHOULD get back where I 'CD’d to I assume(I commented that out, trying to store result in $result and output the result of the CD). Is this a variable scope thing? I just want to see that my commands are actually working before I move further.

#Install Posh-SSH
If(-not(Get-InstalledModule Posh-SSH -ErrorAction silentlycontinue)){
Install-Module Posh-SSH -Confirm:$False -Force
}

$hostCreds = Get-credential -Message "Enter Credentials to connect to Linux host" -UserName "root"
$vihost = "192.168.172.128"
#Connect to linux

$ssh = New-SSHSession -ComputerName $vihost -Credential $hostCreds -AcceptKey
Start-Sleep -Seconds 1
$result = Invoke-SSHCommand $ssh -Command "cd /var/log"
$result.output
#Invoke-SSHCommand $ssh -Command "pwd"
Start-Sleep -Seconds 2
#Invoke-SSHCommand $ssh -Command "/etc/init.d/hostd restart"
#Invoke-SSHCommand $ssh -Command "/etc/init.d/hostd restart"
#Write-Host -ForegroundColor Green "IP Link status on $vihost"
Write-Host -ForegroundColor Yellow "Sleeping for 10 Seconds"
Start-Sleep -Seconds 10
Remove-SSHSession $ssh

#Disconnect from VC and Clear Variables
#Disconnect-VIServer -Server $viHost -Confirm:$false
Remove-Variable * -Force -ErrorAction SilentlyContinue

Just doing cd wil lnot give you any output, you have to use pwd to see where you are now. You can have “cd /var/log && pwd”

If you simply remove .output from your test, you’ll see there is not output but can confirm it did run the command

Host       : 192.168.172.128
Output     : {}
ExitStatus : 0

You could check the exitstatus is equal to 0 instead.

#Install Posh-SSH
If(-not(Get-InstalledModule Posh-SSH -ErrorAction silentlycontinue)){
Install-Module Posh-SSH -Scope Currentuser -Confirm:$False -Force
}

$hostCreds = Get-credential -Message "Enter Credentials to connect to Linux host" -UserName "root"
$vihost = "192.168.172.128"
#Connect to linux

$ssh = New-SSHSession -ComputerName $vihost -Credential $hostCreds -AcceptKey
Start-Sleep -Seconds 1
$result = Invoke-SSHCommand $ssh -Command "cd /var/log"
If($result.exitstatus -eq 0){write-host "Command successful"}
#Invoke-SSHCommand $ssh -Command "pwd"
Start-Sleep -Seconds 2
#Invoke-SSHCommand $ssh -Command "/etc/init.d/hostd restart"
#Invoke-SSHCommand $ssh -Command "/etc/init.d/hostd restart"
#Write-Host -ForegroundColor Green "IP Link status on $vihost"
Write-Host -ForegroundColor Yellow "Sleeping for 10 Seconds"
Start-Sleep -Seconds 10
Remove-SSHSession $ssh

#Disconnect from VC and Clear Variables
#Disconnect-VIServer -Server $viHost -Confirm:$false
Remove-Variable * -Force -ErrorAction SilentlyContinue