«

»

Jan 18

VM Guest Volume Blocksize Report

This is just a quick script I put together for a fellow SA to generate a HTML Report contianing details on the configured volumes for all running Windows Guest VMs. The HTML report shows the Name, Label, Filesystem Type, Allocation Unit (Blocksize), Capacity, and Free Space for each volume in a Windows Guest VM.

The current version can be found here: https://github.com/herseyc/PowerCLI-Scripts/blob/master/VM-BlockSize.ps1

The script is pretty simple. First it prompts for vCenter Credentials and connects to vCenter. It then prompts for Domain User Credentials, which will be used to authenticate against each VM to collect the volume information.

It then gets the IP Addresses of all running Windows VMs, I used IP Addresses since vCenter Inventory names do not always match DNS names. Since I am using Get-VM to retrieve the Guest Information VMware Tools must be installed and running.

The script then loops through the IPs and uses Get-WmiObject to gather the information about the volumes within the VM. Thanks to Stuart Moore’s post Get Cluster size for all disks and volumes on a Windows machine using powershell and wmi for pointing me in the right direction for this.

Finally the HTML for the report is created using ConvertTo-Html and written to the file specified in $ReportFile. The default browser is launched displaying the file.

Here is the PowerShell/PowerCLI Code:

###################################################################
#
# Generates HTML Report of Volume Formatted Filesystem, Blocksize, Capacity, and Free Space
# for all Running Windows VMs
# Usage: VM-BlockSize.ps1
#
# 01/16/2016 - Hersey - http://www.vhersey.com/
#
###################################################################
# Variables
$ReportFile = "C:\Utilities\VMVol.html"
$vCenterFQDN = "192.168.1.27"

############# Here we go ############# 
# Get vCenter Credentials
$vCenterCredential = Get-Credential -Message "vCenter User Credentials"

# Connect to vCenter Server
connect-VIServer $vCenterFQDN -Credential $vCenterCredential

# Get Domain User Credentials
$DomainCredential = Get-Credential -Message "Domain User Credentials"

# Get IP Address of Powered On Windows VMs
$VMs = (get-vm | where {$_.guest.OSFullName -match "Windows" -and $_.PowerState -eq "PoweredOn"} | Get-VMGuest).IPAddress

$report = "<h1>Volume Blocksize Report</h1>"

# Connect to each VM and generate volume report.
foreach ( $vm in $VMs ) {

  $report  = $report + "<h2>Volume Blocksize Report for VM $vm</h2>"

  # Query to get Volume Information
  $wql = "SELECT Label, Blocksize, Name, Capacity, FreeSpace, FileSystem FROM Win32_Volume"

  $voltable = Get-WmiObject -Query $wql -ComputerName $vm -Credential $DomainCredential | ConvertTo-HTML Name, Label, FileSystem, Blocksize, Capacity, FreeSpace -Fragment

  $report = $report + $voltable

}

# Create HTML Report
ConvertTo-Html -Body "$report" -Title "VM Volume Blocksize Report" | Out-File $ReportFile

# Open HTML Report
Start $ReportFile

# Disconnect from vCenter Server
Disconnect-VIServer $vCenterFQDN -confirm:$false

Here is a sample of what the report looks like:

blocksizereport

Enjoy!

Comments are always welcome!

About the author

vHersey

Hersey Cartwright is an IT professional with extensive experience designing, implementing, managing, and supporting technologies that improve business processes. Hersey is Solutions Architect for SimpliVity covering Virginia, Washington DC, and Maryland. He holds the VMware Certified Design Expert (VCDX-DV #128) certification. Hersey actively participates in the VMware community and was awarded the VMware vExpert title in 2016, 2015, 2014, 2013, and 2012. He enjoys working with, teaching, and writing about virtualization and other data center technologies. Follow Hersey on Twitter @herseyc

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

19 + 1 =