Categories: PowerCLI

Script to List Thin provisioned virtual disks with disk size Info

Script to List Thin provisioned virtual disks with disk size Info

It is very useful script for system admins to generate list of virtual machines having thin disks with details to CSV format .

 

Connect-VIServer (MyvCenter) -User (My Username)-Password (My Password)

$report = @()

foreach ($vm in Get-VM){

$view = Get-View $vm

if ($view.config.hardware.Device.Backing.ThinProvisioned -eq $true){

$row = ” | select Name, Provisioned, Total, Used, VMDKs, VMDKsize, DiskUsed, Thin

$row.Name = $vm.Name

$row.Provisioned = [math]::round($vm.ProvisionedSpaceGB , 2)

$row.Total = [math]::round(($view.config.hardware.Device | Measure-Object CapacityInKB -Sum).sum/1048576 , 2)

$row.Used = [math]::round($vm.UsedSpaceGB , 2)

$row.VMDKs = $view.config.hardware.Device.Backing.Filename | Out-String

$row.VMDKsize = $view.config.hardware.Device | where {$_.GetType().name -eq ‘VirtualDisk’} | ForEach-Object {($_.capacityinKB)/1048576} | Out-String

$row.DiskUsed = $vm.Extensiondata.Guest.Disk | ForEach-Object {[math]::round( ($_.Capacity – $_.FreeSpace)/1048576/1024, 2 )} | Out-String

$row.Thin = $view.config.hardware.Device.Backing.ThinProvisioned | Out-String

$report += $row

}}

$report | Sort Name | Export-Csv  “C:\diskinfo.csv”

Out Put 

Name Provisioned Total Used VMDKs VMDKsize DiskUsed Thin
VM 86.19 70 68.65 [DS-01] VM/VM.vmdk 70 52.56 TRUE
Rajesh Radhakrishnan

Share
Published by
Rajesh Radhakrishnan

Recent Posts

NAKIVO Backup & Replication v10.8 Released With New Features

Nakivo has released its new Backup and Replication solution Nakivo v10.8, which includes support for…

2 years ago

Oracle Cloud VMware Solution and Features

Oracle Cloud VMware Solution (OCVS) provides a customer-managed, native VMware-based cloud environment hosted in Oracle…

2 years ago

Vinchin Backup and Recovery Review

Vinchin is a professional provider of data protection solutions for enterprises. It provides a series…

2 years ago

VMware Cloud Disaster Recovery (VCDR) Solution Deployment And Configuration Part 2

In my previous blog post, I have explained about VMware Cloud Disaster Recovery (VCDR) Onboarding and…

2 years ago

How to Deploy vRNI Cloud With VMC on AWS

vRealize Network Insight helps you build an optimized, highly available, and secure network infrastructure across…

2 years ago

This SysAdmin Day, WIN with Hornetsecurity!

Can you believe it's here again? SysAdmin Day is back, and with it comes endless gratitude…

2 years ago