VMware Cloud Community
PGinhoux
Enthusiast
Enthusiast
Jump to solution

VM.Guest.Disk doesn't list the NFS filesystem of a linux server

Hi,

Last week, I posted the same question in the Automation category, but I don't find it today, so I open it again.

My problem is as follows :

I use the following script I had found (thanks for those who published it) to list all the FS on my VMs:

ForEach ($VM in (Get-VM |Get-View)){($VM.Guest.Disk |Select @{N=“Name“;E={$VM.Name}},DiskPath, @{N=“Capacity(MB)“;E={[math]::Round($_.Capacity/ 1MB)}}, @{N=“Free Space(MB)“;E={[math]::Round($_.FreeSpace / 1MB)}}, @{N=“Free Space %“;E={[math]::Round(((100 * ($_.FreeSpace))/ ($_.Capacity)),0)}}) | Format-Table}

But the VM.Guest.Disk doesn't list the NFS FS.

Example of result for one VM :

Name DiskPath Capacity(MB) Free Space(MB) Free Space %
---- -------- ------------ -------------- ------------
vm-prdf-bdd1 / 2960 1431 48
vm-prdf-bdd1 /system 120 92 77
vm-prdf-bdd1 /images 3904 3665 94
vm-prdf-bdd1 /home 976 905 93
vm-prdf-bdd1 /boot 488 394 81
vm-prdf-bdd1 /opt 976 743 76
vm-prdf-bdd1 /opt/mysql 476 353 74
vm-prdf-bdd1 /opt/mysql/na/5.6.33 968 741 77
vm-prdf-bdd1 /tmp 864 779 90
vm-prdf-bdd1 /var 1856 1011 54
vm-prdf-bdd1 /var/tmp 864 779 90

The "df" command shows more than the above list :

[root@vm-prdf-bdd1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-root_lv 2.9G 1.4G 1.4G 49% /
devtmpfs 491M 0 491M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 460K 497M 1% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/mapper/rootvg-system_lv 120M 20M 92M 18% /system
/dev/mapper/infravg-images_lv 3.9G 19M 3.6G 1% /images
/dev/mapper/rootvg-home_lv 976M 3.4M 906M 1% /home
/dev/sda1 488M 59M 394M 13% /boot
/dev/mapper/rootvg-opt_lv 976M 167M 742M 19% /opt
/dev/mapper/infravg-mysql_lv 477M 95M 353M 22% /opt/mysql
/dev/mapper/infravg-mysql_na_5633_lv 969M 161M 742M 18% /opt/mysql/na/5.6.33
/dev/mapper/rootvg-tmp_lv 864M 26M 780M 4% /tmp
/dev/mapper/rootvg-var_lv 1.9G 689M 1.1G 40% /var
<IP address>:/nfs-data-fi-ds/prdf/bdd 512G 29G 484G 6% /myqdata/mymvtdb

The /mtqdata/mymvtdb is a NFS share as the mount command shows it :

<IP address>:/nfs-data-fi-ds/prdf/bdd on /myqdata/mymvtdb type nfs4 (rw,nosuid,nodev,noatime,vers=4.0,rsize=32768,wsize=32768,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=<IP address>,local_lock=none,addr=<IP address>)

Can somebody explain me why the script doesn't list all the FS, if there is a way to get it ?

Thanks in advance for the help.

Regards.

Patrick

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That 2nd script in your last reply works without an issue for me.

In your 1st script you use the foreach statement, which is not the same as the Foreach-Object cmdlet.
The foreach statement doesn't place any thing in the pipeline, so the Export-Csv complains it sees an empty pipeline.
The Foreach-Object cmdlet does place objects in the pipeline, so you can safely "pipe' the results to the Export-Csv cmdet.


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

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

If you look at the GuestInfo object in the API Reference, it doesn't list NFS in the description of the Disk property.
It says "Ext2, Ext3, Ext4, ReiserFS, XFS, Btrfs, NTFS, VFAT, UFS, PCFS, HFS, and MS-DOS".

And the latest VMware Tools User Guide doesn't seem to list NFS either.
So that probably explains why you are not seeing the NFS filesyst(s).

You could use the Invoke-VMScript cmdlet and run the 'df' command inside the Guest OS.


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

0 Kudos
PGinhoux
Enthusiast
Enthusiast
Jump to solution

Hi,

Thanks for pointing me on the API reference doc. Maybe in a next VMware release (7.0 ?), there will be more file system type available for this command.

I tried then the  Invoke-VMScript cmdlet which is good for me. I get all the FS available on my vm :

Invoke-VMScript -VM "VM-PRDF-bdd1" -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1

ScriptOutput
-----------------------------------------------------------------------------------------------------------------------| Filesystem Size Used Avail
Use% Mounted on
| /dev/mapper/rootvg-root_lv 2.9G 1.4G 1.4G 49% /
| devtmpfs 491M 0 491M 0% /dev
| tmpfs 497M 0 497M 0% /dev/shm
| tmpfs 497M 460K 497M 1% /run
| tmpfs 497M 0 497M 0% /sys/fs/cgroup
| /dev/mapper/rootvg-system_lv 120M 20M 92M 18% /system
| /dev/mapper/infravg-images_lv 3.9G 19M 3.6G 1% /images
| /dev/mapper/rootvg-home_lv 976M 3.4M 906M 1% /home
| /dev/sda1 488M 59M 394M 13% /boot
| /dev/mapper/rootvg-opt_lv 976M 167M 742M 19% /opt
| /dev/mapper/infravg-mysql_lv 477M 95M 353M 22% /opt/mysql
| /dev/mapper/infravg-mysql_na_5633_lv 969M 161M 742M 18% /opt/mysql/na/5.6.33
| /dev/mapper/rootvg-tmp_lv 864M 26M 780M 4% /tmp
| /dev/mapper/rootvg-var_lv 1.9G 701M 1.1G 41% /var
| <IP adress>:/nfs-data-fi-ds/prdf/bdd 512G 29G 484G 6% /myqdata/mymvtd

Now all my attempts to get the same for all vms in my cluster failed.

Either I didn't get any result :

$report = foreach($vm in $vms)
{
$vvm = $vm.vmname
$dflist = Invoke-VMScript -VM $vvm -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1
"" | select
@{N='vmname' ;E={$vvm}},
@{N='DF list';E={$dflist.ScriptOutput}}
}
$report | Export-Csv -Path "C:\Temp\VMS-check.csv" -NoTypeInformation -UseCulture

or I have the same error for each VM  :

$report = foreach ($VM in (Get-VM |Get-View))
{
$vvm = $vm.vmname
$dflist = Invoke-VMScript -VM $vvm -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1
"" | Select
@{N='vmname';E={$vvm}},
@{N='BuildNumber';E={$dflist.ScriptOutput}}
}
$report | Export-Csv -Path "C:\Temp\VMS-check.csv" -NoTypeInformation -UseCulture

Invoke-VMScript : 12/12/2022 15:21:05 Invoke-VMScript Value cannot be found for the mandatory parameter VM
At line:6 char:12

The $vvm parameter seems not correct in the Invoke-VMScript but I don't understand why.

So I need help on this script, if possible.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you try with

 

$report = foreach ($VM in Get-VM))
{
  $dflist = Invoke-VMScript -VM $VM -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1
  "" | Select @{N='vmname';E={$VM.Name}},
    @{N='BuildNumber';E={$dflist.ScriptOutput}}
}

$report | Export-Csv -Path "C:\Temp\VMS-check.csv" -NoTypeInformation -UseCulture

 


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

0 Kudos
PGinhoux
Enthusiast
Enthusiast
Jump to solution

Well, the result is quite strange :

"Length"
"0"


"0"

I get some credential errors for some vms which is normal for the Windows vm that I would need to exclude, but there are no other error during the run.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I just used your code, there were no parameters on the Select cmdlet.
I changed the code above.


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

0 Kudos
PGinhoux
Enthusiast
Enthusiast
Jump to solution

I changed the script, first to run it on only the linux VM and to add parameters on the select cmdlet as follows :

$vmlist = Get-VM -PipelineVariable vm | Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Linux' }

$report = foreach($vm in $vmList){
$dflist = Invoke-VMScript -VM $VM -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1
"" | Select @{N='vmname';E={$VM.Name}},
@{N='DF List';E={$dflist.ScriptOutput}}
}

$report | Export-Csv -Path "C:\Temp\VM-DFList.csv" -NoTypeInformation -UseCulture

Extract of the result which is now better :

"vmname";"DF List"
"vm-testsyslog";"Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-root_lv 2.9G 1.2G 1.6G 44% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.8M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 488M 80M 374M 18% /boot
/dev/mapper/infravg-images_lv 3.9G 24M 3.6G 1% /images
/dev/mapper/rootvg-system_lv 120M 8.4M 103M 8% /system
/dev/mapper/rootvg-home_lv 976M 2.6M 907M 1% /home
/dev/mapper/rootvg-opt_lv 976M 818M 92M 90% /opt
/dev/mapper/infravg-bladelogic_v89_lv 976M 111M 799M 13% /opt/bladelogic/v89
/dev/mapper/rootvg-tmp_lv 864M 26M 780M 4% /tmp
/dev/mapper/rootvg-var_lv 1.9G 1.8G 0 100% /var
/dev/mapper/infravg-syslog_lv 9.8G 37M 9.2G 1% /mnt/log
"
"vm-prdf-prv1";"Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-root_lv 2.9G 1.2G 1.6G 42% /
devtmpfs 491M 0 491M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 488K 497M 1% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/mapper/rootvg-system_lv 120M 20M 92M 18% /system
/dev/mapper/rootvg-home_lv 976M 2.6M 907M 1% /home
/dev/sda1 488M 59M 394M 13% /boot
/dev/mapper/infravg-images_lv 3.9G 1.7G 2.0G 46% /images
/dev/mapper/rootvg-tmp_lv 864M 26M 780M 4% /tmp
/dev/mapper/rootvg-opt_lv 976M 164M 745M 19% /opt
/dev/mapper/infravg-tomcat_lv 47M 2.3M 41M 6% /opt/tomcat
/dev/mapper/infravg-ant_1.9.6_lv 93M 38M 49M 44% /opt/ant/1.9.6
/dev/mapper/rootvg-var_lv 1.9G 638M 1.1G 37% /var
/dev/mapper/infravg-jdksun64_1.8.0_60_lv 477M 352M 96M 79% /opt/jdksun64/1.8.0_60
/dev/mapper/infravg-tomcat_8.0.27_lv 969M 22M 881M 3% /opt/tomcat/8.0.27
/dev/mapper/infravg-analysis_2.0.8_lv 93M 65M 22M 76% /opt/analysis/2.0.8
/dev/mapper/infravg-prov_lv 969M 21M 883M 3% /opt/application/prov
/dev/mapper/infravg-prov_dump_lv 3.8G 99M 3.5G 3% /opt/application/prov/dump

Actually, I thought that writing the Select cmdlet, then the parameters aligned on the same column on the lines after, to make to script more easy to read, will produce the same result.  It was my mistake.

So is there a specific syntax to write the Select then the parameters on diffrent lines ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

For the Select the ScriptOutput is one big blob of text, including CRs.
I would split the returned text in separate lines, and show 1 line per row in the output.


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Something like this for example

Get-VM -PipelineVariable vm |
ForEach-Object -Process {
  $result = Invoke-VMScript -VM $VM -ScriptText "df -h" -GuestUser Login1  -GuestPassword Password1
  $result.ScriptOutput.Split("`n") |
  where{$_ -notmatch 'Filesystem' -and $_ -ne ''} |
  ForEach-Object -Process {
    New-Object -TypeName PSObject -Property ([ordered]@{
      VM = $vm.Name
      FileSystem = $_
    })
  }
} |
Export-Csv -Path 'C:\Temp\VMS-check.csv' -NoTypeInformation -UseCulture


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

0 Kudos
PGinhoux
Enthusiast
Enthusiast
Jump to solution

Your script returns a result that is then similar as the one create using the VM-GetDisk cmdlet. 

And you're right, it is easily reusable for further analysis.

So I added the command to run your script for only Linux VM; but it fails with the error below :

$vmlist = Get-VM -PipelineVariable vm | Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Linux' }
foreach($vm in $vmList) {
$result = Invoke-VMScript -VM $VM -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1
$result.ScriptOutput.Split("`n") |
where{$_ -notmatch 'Filesystem' -and $_ -ne ''} |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VM = $vm.Name
FileSystem = $_
})
}
} |
Export-Csv -Path 'C:\Temp\VM-DFList-2.csv' -NoTypeInformation -UseCulture
At line:12 char:3
+ } |
+ ~
An empty pipe element is not allowed.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : EmptyPipeElement

Can you explain why I get this error, and this script seems closed to yours ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Why did you change the Foreach-Object in a foreach?
The foreach statement doesn't place anything in the pipeline.


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

0 Kudos
PGinhoux
Enthusiast
Enthusiast
Jump to solution

I'm confused now because the previous script, I use, started with the same cmdlets  to select Linux VM and didn't report any errors :

$vmlist = Get-VM -PipelineVariable vm | Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Linux' }

$report = foreach($vm in $vmList){
$dflist = Invoke-VMScript -VM $VM -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1
"" | Select @{N='vmname';E={$VM.Name}},
@{N='DF List';E={$dflist.ScriptOutput}}
}

$report | Export-Csv -Path "C:\Temp\VM-DFList.csv" -NoTypeInformation -UseCulture

So to get a well-formatted result, I did the same change in your script, expecting it to work fine, but as I got an error, I use this method :

Get-VM -PipelineVariable vm |
Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Linux' } |
ForEach-Object -Process {
$result = Invoke-VMScript -VM $VM -ScriptText "df -h" -GuestUser Login1 -GuestPassword Password1
$result.ScriptOutput.Split("`n") |
where{$_ -notmatch 'Filesystem' -and $_ -ne ''} |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VM = $vm.Name
FileSystem = $_
})
}
} |
Export-Csv -Path 'C:\Temp\VM-DFList-3.csv' -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That 2nd script in your last reply works without an issue for me.

In your 1st script you use the foreach statement, which is not the same as the Foreach-Object cmdlet.
The foreach statement doesn't place any thing in the pipeline, so the Export-Csv complains it sees an empty pipeline.
The Foreach-Object cmdlet does place objects in the pipeline, so you can safely "pipe' the results to the Export-Csv cmdet.


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

0 Kudos
PGinhoux
Enthusiast
Enthusiast
Jump to solution

Thanks for all of these details which really help me.

I can close this subject now.

0 Kudos