Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • 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 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

February 20, 2023 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

How to Connect VPN Before Windows Logon

November 14, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 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

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • Configuring Port Forwarding in Windows
  • Start Menu or Taskbar Search Not Working in Windows 10/11
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Adding Drivers into VMWare ESXi Installation Image
  • How to Hide Installed Programs in Windows 10 and 11
  • Configuring SFTP (SSH FTP) Server on Windows
Footer Logo

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


Back To Top