Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Virtualization / VMWare / Checking Free Space on VMFS Datastores via PowerCLI

June 8, 2021 PowerShellVMWare

Checking Free Space on VMFS Datastores via PowerCLI

In this article we’ll show a simple PowerCLI script to check the amount of free space on VMWare vSphere datastores and detect Thin Provisioning datastores with the total size of virtual machine thin virtual disks (dynamically expanding) exceeding the total size of the datastore. If you have multiple VMWare datastores in your infrastructure, it is easy to use this PowerShell script to monitor the amount of free space and detect datastores with storage overcommitment (the space requirements for thin disks of all VMs are greater than the available space on VMFS datastore). You can use the script to analyze the growth of used space, prior to creating a VM, to find datastores with Thin Provision overcommitment, etc.

In order your vSphere infrastructure to work correctly, it is recommended to have at least 5-10% of free space on your VMWare VMFS datastore. If you are using snapshots (including those created by the backup system), it is necessary to have at least 10-15% of free space.

To check and display the amount of free space on VMWare datastore, you can use the PowerShell script below (it is supposed that VMWare vSphere PowerCLI module is already installed on your computer):

# Import the PowerCLI module into your PowerShell session
Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Connect to vCenter host
Connect-VIServer mun-vcsa1 -User admin
# Get the list of vCenter darastores
$datastores = Get-Datastore
$ErrorActionPreference = 'SilentlyContinue'
# loop through all available datastores
ForEach ($datastore in $datastores)
{
# Find the size of the committed space of all thin disks in a datastore (how much space it is required if all vmdk files will grow to the sizes specified in their settings)
$Provision = ([Math]::Round(($datastore.ExtensionData.Summary.Capacity - $datastore.ExtensionData.Summary.FreeSpace + $datastore.ExtensionData.Summary.Uncommitted)/1GB,0))
# Percentage of free space in the datastore
$PerFree = ([math]::Round(($datastore.FreeSpaceGB)/($datastore.CapacityGB)*100,2))
# Percentage of thin disk overcommitment
$PerOvercommit = ([math]::Round($Provision/($datastore.CapacityGB)*100,2))
# Add extra properties to the datastore object
$datastore | Add-Member -type NoteProperty -name PercentsFree -value $PerFree
$datastore | Add-Member -type NoteProperty -name CapacityGb_r -value ([Math]::Round(($datastore.ExtensionData.Summary.Capacity)/1GB,0))
$datastore | Add-Member -type NoteProperty -name FreeSpaceGb_r -value ([Math]::Round(($datastore.ExtensionData.Summary.FreeSpace)/1GB,0))
$datastore | Add-Member -type NoteProperty -name ProvisionedSpaceGb -value $Provision
$datastore | Add-Member -type NoteProperty -name PercentsOvercommit -value $PerOvercommit
}
# Display the resulting data on VMWare datastores and export the output to a CSV file
$datastores|select-object Name, Type, Datacenter,CapacityGb_r,FreeSpaceGb_r,PercentsFree,ProvisionedSpaceGb,PercentsOvercommit|sort PercentsFree| Export-Csv C:\Reports\VMWareVMFSDatastores.csv -NoTypeInformation

Get free space of all VMWare VMFS Datastores with PowerCLI

If you try to connect to vCenter using Connect-VIServer and see the error:

Could not resolve the requested VC server.Additional Information: There was no endpoint listening at https://mun-vcsa1/sdk that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details

it is likely that PowerCLI tries to connect to VCSA via proxy. Run PowerCLIConfiguration and check if UseSystemProxy returns. If it is, disable the system proxy for PowerCLI using this command:

Set-PowerCliConfiguration -proxypolicy noproxy

In my example, you can see that the first 5 VMFS datastores have less than 5% of free space left (the green box). There is storage overcommitment on some datastores (the total size of all thin virtual disks in the datastores exceeds their size). If your virtual VM disks start to grow to their maximum size specified in their settings, you may get out of space on your VMFS/NFS/VVOL storages. (Running VMs with thick disks will work as usual, but you will not be able to start new VMs, since there will be no space to create a VSWAP file.) The datastores with the committed space that is larger than the total LUN size are highlighted in yellow.
Find the VMFS datastore with most free space using PowerShell

This PowerShell script will help you to quickly find VMWare datastores with the lack of free space (you can migrate VMs from the datastore using Storage vMotion).

0 comment
2
Facebook Twitter Google + Pinterest
previous post
How to Check, Enable or Disable SMB Protocol Versions on Windows?
next post
Using Windows Defender Antivirus on Windows Server 2019 and 2016

Related Reading

Using Previous Command History in PowerShell Console

January 31, 2023

How to Install the PowerShell Active Directory Module...

January 31, 2023

Finding Duplicate E-mail (SMTP) Addresses in Exchange

January 27, 2023

How to Disable or Uninstall Internet Explorer (IE)...

January 26, 2023

How to Delete Old User Profiles in Windows?

January 25, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Configure User’s Folder Redirection with Group Policy

    February 3, 2023
  • Using Previous Command History in PowerShell Console

    January 31, 2023
  • How to Install the PowerShell Active Directory Module and Manage AD?

    January 31, 2023
  • Finding Duplicate E-mail (SMTP) Addresses in Exchange

    January 27, 2023
  • How to Delete Old User Profiles in Windows?

    January 25, 2023
  • How to Install Free VMware Hypervisor (ESXi)?

    January 24, 2023
  • How to Enable TLS 1.2 on Windows?

    January 18, 2023
  • Allow or Prevent Non-Admin Users from Reboot/Shutdown Windows

    January 17, 2023
  • Fix: Can’t Extend Volume in Windows

    January 12, 2023
  • Wi-Fi (Internet) Disconnects After Sleep or Hibernation on Windows 10/11

    January 11, 2023

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Configuring Port Forwarding in Windows
  • Installing RSAT Administration Tools on Windows 10 and 11
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • Start Menu or Taskbar Search Not Working in Windows 10/11
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • How to Hide Installed Programs in Windows 10 and 11?
  • Adding Drivers into VMWare ESXi Installation Image
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top