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