Posted in PowerCLI Script

Capacity Used and Capacity Free for your VMs

Capacity Used and Capacity Free for your VMs Posted on 27/10/2017

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 {
This cmdlet 
Show-VMDisk -Name MyVM 
Show all disks for VM name MYVM. You can use * for all 
Specifie the vm name. 



$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