VMware Cloud Community
hoon0715
Contributor
Contributor
Jump to solution

Can I export the 'df -h' command information of VCSA to CSV?

Hi, all.

 

I don't know Powercli very well.
However, I'd like to export the 'df -h' command information of VCSA to csv as the title.
 
If this is possible, please tell me how to export only the parts '/' , '/storage/log' and '/storage/db'.
 
Thanks in advance.
Best regards.
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
hoon0715
Contributor
Contributor
Jump to solution

Thanks for reply !

 

However, it doesn't work... ;-(

hoon0715_0-1661933978946.png

 

I think this is because when I access vcsa with SSH, I can't access to BASH shell right away.

hoon0715_1-1661934069330.png

 

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? 😂

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

hoon0715
Contributor
Contributor
Jump to solution

It works so perfectly!
Thanks a lot @LucD  :-))
0 Kudos