PowerCLI

  • 1.  Guest Free Space

    Posted Apr 26, 2012 08:09 AM

    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



  • 2.  RE: Guest Free Space
    Best Answer

    Posted Apr 26, 2012 09:26 AM

    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 


  • 3.  RE: Guest Free Space

    Posted Apr 26, 2012 04:13 PM

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