Hi, all.
You can use the SSH stream in that case
$user = 'root'
$pswd = 'VMware1!' # Change to your password
$cred = New-Object -TypeName PSCredential -ArgumentList ($user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force))
$session = New-SSHSession -ComputerName $global:DefaultVIServer.Name -Credential $cred -AcceptKey
$stream = New-SSHShellStream -SSHSession $session -TerminalName tty
$stream.WriteLine('shell')
while($stream.Read() -notmatch "root\@"){
Start-Sleep 1
}
$stream.WriteLine('df -h')
$txt = $stream.Read()
while ($txt -notmatch 'Filesystem')
{
Start-Sleep 1
$txt = $stream.Read()
}
$stream.Close()
$txt.Split("`n") | Where-Object { $_ -match '\/\r$|\/storage\/log\r$|\/storage\/db\r$' }
Remove-SSHSession -SSHSession $session | Out-Null
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you have SSH access to the VCSA and you have the Posh-SSH module installed, you can do
$user = 'root'
$pswd = 'VMware1!' # Change to your password
$cred = New-Object -TypeName PSCredential -ArgumentList ($user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force))
$session = New-SSHSession -ComputerName $global:DefaultVIServer.Name -Credential $cred -AcceptKey
$result = Invoke-SSHCommand -SSHSession $session -Command 'df -h'
Remove-SSHSession -SSHSession $session | Out-Null
$result.Output.Split("`n") | Where-Object { $_ -match '\/$|\/storage\/log$|\/storage\/db$' }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for reply !
However, it doesn't work... ;-(
I think this is because when I access vcsa with SSH, I can't access to BASH shell right away.
It can permanently change the shell of VCSA using the "chsh -s /bin/bash root" command, but it is difficult to use at multiple sites.
How shall I do it? 😂
You can use the SSH stream in that case
$user = 'root'
$pswd = 'VMware1!' # Change to your password
$cred = New-Object -TypeName PSCredential -ArgumentList ($user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force))
$session = New-SSHSession -ComputerName $global:DefaultVIServer.Name -Credential $cred -AcceptKey
$stream = New-SSHShellStream -SSHSession $session -TerminalName tty
$stream.WriteLine('shell')
while($stream.Read() -notmatch "root\@"){
Start-Sleep 1
}
$stream.WriteLine('df -h')
$txt = $stream.Read()
while ($txt -notmatch 'Filesystem')
{
Start-Sleep 1
$txt = $stream.Read()
}
$stream.Close()
$txt.Split("`n") | Where-Object { $_ -match '\/\r$|\/storage\/log\r$|\/storage\/db\r$' }
Remove-SSHSession -SSHSession $session | Out-Null
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference