Capacity Used and Capacity Free for your VMs

I introduce you a new script for list the capacity used and capacity free on your VMs. To use this script, run PowerCLI and add this function.

To add this new function run this command line :

PowerCLI C:\> . C:\Users\Administrator\Desktop\ShowFreeSpace.ps1

Have Fun !!

#Verifier la taille des disques de vos VMs
#Script By Olivier Gosselin - France
#Tools PowerCLI 6.5 Release 1

$vCenterFQDN = "YourvCenterServer"
$ConnectTovCenter = Get-Credential
Connect-VIServer $vCenterFQDN -Credential $ConnectTovCenter

function Show-VMDisk {
 <# 
.SYNOPSIS 
This cmdlet 
.DESCRIPTION 
.EXAMPLE 
Show-VMDisk -Name MyVM 
Show all disks for VM name MYVM. You can use * for all 
.INPUTS 
None 
.PARAMETER Name 
Specifie the vm name. 
.LINK 
http://www.purplescreen.eu/
#>
 [CmdletBinding()]

 Param(
 [Parameter(Mandatory=$True,Position=0)]
 [array]$Name

)#PARAM

$MyVMs = Get-VM -name $Name

foreach ($MyVM in $MyVMs) {
 $MyVMPaths = @($MyVM.Guest.Disks.Path)
 $ToolsVM = $MyVM.ExtensionData.Guest.ToolsStatus
 if ($ToolsVM -eq "toolsOk") {

foreach ($MyVMPath in $MyVMPaths) {
 $DetailsPath = $MyVM.Guest.Disks | where {$_.path -eq "$MyVMPath"}
 $CapacityGB = $DetailsPath.CapacityGB
 $FreeSpaceGB = $DetailsPath.FreeSpaceGB

$ShowCapacityGB = ([math]::round($CapacityGB, 2))
 $ShowFreeyGB = ([math]::round($FreeSpaceGB, 2))

$SizeOutput = New-Object psobject
 $SizeOutput | Add-Member -MemberType NoteProperty -Name Name -Value $MyVM.Name
 $SizeOutput | Add-Member -MemberType NoteProperty -Name Lecteur -Value $MyVMPath
 $SizeOutput | Add-Member -MemberType NoteProperty -Name CapacityUseGB -Value $ShowCapacityGB
 $SizeOutput | Add-Member -MemberType NoteProperty -Name FreeSpaceGB -Value $ShowFreeyGB
 $SizeOutput
 }
 }
 }
 }