Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

The following can do this (there seems to be an error in your code).

It assumes that you have the Posh-SSH module installed (see Use Posh-SSH instead of PuTTY)

$esxName = 'MyEsx'

$cred = Get-Credential -Message "Credentials for $esxName"

$esx = Get-VMHost -Name $esxName

$cmdSub = @'

days=$(awk -F":" '$1 == "root" {print $3}' /etc/shadow)

seconds_since_epoch=$((days*60*60*24))

date --date=@$((seconds_since_epoch))

'@


$session = New-SSHSession -ComputerName $esx.Name -Credential $cred -AcceptKey

$result = Invoke-SSHCommand -SSHSession $session -Command $cmdSub

Remove-SSHSession -SSHSession $session | Out-Null


$result.Output


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos