Hi,
I am unable to get free space of VM level. Please help
function get-mysummary() {
param(
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Folder]$Folder,
[switch]$Recursion
)
$report = @()
$vms = Get-VM -Location $Folder -NoRecursion:(-not $Recursion)
if($vms.Count -gt 0){
$report += Get-VM -Location $Folder -NoRecursion:(-not $Recursion) |
Select Folder, Name,
@{N = "IP Address"; E = {@($_.guest.IPAddress[0])}},
@{N="VM PowerState";E={@($_.PowerState)}},
@{N="OS"; E={@($_.guest.OSFullName)}},
@{N = "CPU"; E = {@($_.NumCPU)}},
@{N = "Memory (GB)"; E = {@($_.MemoryGB)}},
@{N = "Provisioned (GB)"; E = {[math]::Round($_.provisionedspacegb)}}
@{N="FreeSpace(GB)";E={[math]::Round($_.FreeSpace / 1GB)}},
@{N="FreeSpace(%)";E={[math]::Round(((100* ($_.FreeSpace))/($_.Capacity)),0)}},
@{N="UsedSpace(GB)";E={[math]::Round(((($_.Capacity / 1GB))-($_.FreeSpace / 1GB)),0)}})
}
The above command shows blank for Freespace
Try like this
param(
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Folder]$Folder,
[switch]$Recursion = $false
)
$vms = Get-VM -Location $Folder -NoRecursion:(-not $Recursion)
if ($vms.Count -gt 0) {
$vms | Select Folder, Name,
@{N = "IP Address"; E = {@($_.guest.IPAddress[0])}},
@{N = "VM PowerState"; E = {@($_.PowerState)}},
@{N = "OS"; E = {@($_.guest.OSFullName)}},
@{N = "CPU"; E = {@($_.NumCPU)}},
@{N = "Memory (GB)"; E = {@($_.MemoryGB)}},
@{N = "Provisioned (GB)"; E = {[math]::Round($_.provisionedspacegb)}},
@{N = "FreeSpace(GB)"; E = {
$script:vdiskFree = ($_.Guest.Disks | Measure-Object -Property FreeSpaceGB -Sum).Sum
$script:vdiskCapacity = ($_.Guest.Disks | Measure-Object -Property CapacityGB -Sum).Sum
[math]::Round($script:vdiskCapacity, 0)}},
@{N = "FreeSpace(%)"; E = {[math]::Round($script:vdiskFree / $script:vdiskCapacity * 100, 0)}},
@{N = "UsedSpace(GB)"; E = {[math]::Round($script:vdiskCapacity - $script:vdiskFree, 0)}}
}
}
Get-Folder |
ForEach-Object -Process {
get-mysummary -Folder $_
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
FreeSpace and Used Space are properties on a Datastore object, not a VM object.
What kind of value do you want to see in this report?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I would like to see the total available free space on the VM, along with the provisioned space.
Please help.
Try like this
param(
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Folder]$Folder,
[switch]$Recursion = $false
)
$vms = Get-VM -Location $Folder -NoRecursion:(-not $Recursion)
if ($vms.Count -gt 0) {
$vms | Select Folder, Name,
@{N = "IP Address"; E = {@($_.guest.IPAddress[0])}},
@{N = "VM PowerState"; E = {@($_.PowerState)}},
@{N = "OS"; E = {@($_.guest.OSFullName)}},
@{N = "CPU"; E = {@($_.NumCPU)}},
@{N = "Memory (GB)"; E = {@($_.MemoryGB)}},
@{N = "Provisioned (GB)"; E = {[math]::Round($_.provisionedspacegb)}},
@{N = "FreeSpace(GB)"; E = {
$script:vdiskFree = ($_.Guest.Disks | Measure-Object -Property FreeSpaceGB -Sum).Sum
$script:vdiskCapacity = ($_.Guest.Disks | Measure-Object -Property CapacityGB -Sum).Sum
[math]::Round($script:vdiskCapacity, 0)}},
@{N = "FreeSpace(%)"; E = {[math]::Round($script:vdiskFree / $script:vdiskCapacity * 100, 0)}},
@{N = "UsedSpace(GB)"; E = {[math]::Round($script:vdiskCapacity - $script:vdiskFree, 0)}}
}
}
Get-Folder |
ForEach-Object -Process {
get-mysummary -Folder $_
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
As per the output, I am seeing difference between provisioned, free space and used space
Name | IP Address | VM PowerState | OS | CPU | Memory (GB) | Provisioned (GB) | FreeSpace(GB) | FreeSpace(%) | UsedSpace(GB) |
Myvm1 | 10.10.10 | PoweredOn | Microsoft Windows Server 2012 (64-bit) | 2 | 4 | 54 | 50 | 65 | 17 |
when I add freespace and usedspace it is not matching with provisioned space
That is because Provisioned is seen from the outside, it is the space allocated to a vDisk when you created the VM.
The FreeSpace and UsedSpace is from inside the guest OS (obtained through VMware Tools).
When your vDisk is of type Thin, vSphere is not giving you that physical space immediately, it is extended as usage grows.
The guest OS sees the allocated size, not the provisioned space.f
Example:
- a VMDK of type Thin, with size 60 GB
- the VMDK starts with allocated space 0, which grows as you place data on the disk
- the guest OS sees the harddisk always as 60 GB
And don't forget that there is overhead.
A VMDK of 60 GB, will not be exactly 60 GB of usable storage inside the guest OS.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi, this script gets a VM´s disks and lists total, free and free% space:
# Get VM disk space usage
Clear-Variable -name Output
$Output = @()
$cluster = Get-Cluster "clustername"
ForEach ($VM in $cluster | Get-VM | where-object {($_.powerstate -ne "PoweredOff")})
{
ForEach ($Drive in $VM.Extensiondata.Guest.Disk)
{
$Path = $Drive.DiskPath
#Calculations
$Freespace = [math]::Round($Drive.FreeSpace / 1MB)
$Capacity = [math]::Round($Drive.Capacity/ 1MB)
$SpaceOverview = "$Freespace" + "/" + "$capacity"
$PercentFree = [math]::Round(($FreeSpace)/ ($Capacity) * 100)
$Output = $Output + "Vm: " + $VM.Name + "`n"
$Output = $Output + "Disk: " + $Path + "`n"
$OutPut = $Output + "Free(MB): " + $Freespace + "`n"
$Output = $Output + "Free(%): " + $PercentFree + "`n"
$Output = $Output + "Capacity: " + $Capacity + "`n"
write-host $VM.name $path $Capacity "Total " $Freespace "Free " $PercentFree "%Free "
}
}
Results look like this:
computername D:\ 40957 Total 37061 Free 90 %Free
computername C:\ 76448 Total 48177 Free 63 %Free
Maybe this works for you?
Hi LucD,
After replacing the below line from
[math]::Round($script:vdiskCapacity, 0)}},
To
[math]::Round($script:vdiskCapacity - ($script:vdiskCapacity - $script:vdiskFree), 0)}},
I am getting the desired output.
Thank you very much for your help as always
Hi,
I was looking for total VM disk space used and free.
Thanks for your time and help