VMware Cloud Community
Troy_Clavell
Immortal
Immortal
Jump to solution

Guest Free Space

the below code works great against a 5.0 vCenter instance but does not work against vCenter 5.0U1.  Any thoughts as to why?

Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VmName -ExpandProperty Disks | Select VmName, Path, @{ N="PercFree"; E={ [math]::Round( ( 100 * ( $_.FreeSpace / $_.Capacity ) ),0 ) } } | Sort PercFree | Export-Csv C:\scripts\freespace.csv -NoTypeInformation

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.0.1 build 581491
---------------
Snapin Versions
---------------
   VMware AutoDeploy PowerCLI Component 5.0 build 544967
   VMware ImageBuilder PowerCLI Component 5.0 build 544967
   VMware License PowerCLI Component 5.0 build 544881
   VMware vSphere PowerCLI Component 5.0 build 581435

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect that is due to a powered off VM that has lost it's cached information obtained through VMware Tools.

In that case the Disks property will be $null and the ExpandProperty has a problem with that.

But I'm not sure if this is new in PowerCLI 5.0.1, this is afaik a PowerShell feature.

You can avoid those by adding an additional Where-clause

Get-VM  | where { $_.PowerState -eq "PoweredOn" } | 
Get-VMGuest | 
where {$_.Disks} | Select VmName -ExpandProperty Disks | 
Select VmName, Path, @{ N="PercFree"; E={ [math]::Round( ( 100 * ( $_.FreeSpace / $_.Capacity ) ),0 ) } } | 
Sort PercFree | Export-Csv C:\scripts\freespace.csv -NoTypeInformation 


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect that is due to a powered off VM that has lost it's cached information obtained through VMware Tools.

In that case the Disks property will be $null and the ExpandProperty has a problem with that.

But I'm not sure if this is new in PowerCLI 5.0.1, this is afaik a PowerShell feature.

You can avoid those by adding an additional Where-clause

Get-VM  | where { $_.PowerState -eq "PoweredOn" } | 
Get-VMGuest | 
where {$_.Disks} | Select VmName -ExpandProperty Disks | 
Select VmName, Path, @{ N="PercFree"; E={ [math]::Round( ( 100 * ( $_.FreeSpace / $_.Capacity ) ),0 ) } } | 
Sort PercFree | Export-Csv C:\scripts\freespace.csv -NoTypeInformation 


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

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

the where-clause was the key.  Thank you sir!

Reply
0 Kudos