This script has the following Requirements:

  • VI Toolkit
  • Powershell
  • WMI query
  • Windows VM’s

The following script get al lists of all Windows VM’s which are powered on. The next step is a WMI query which queries the Win32_DiskPartition class. The final step is a match with the $StartingOffset variable.

Add-PSSnapIn VMware.VimAutomation.Core

# Connect to vCenter
$VC = Connect-VIServer (Read-Host "Enter vCenter server")

$StartingOffset = "65536"

# Get all VM’s with powerstate = PoweredOn
$VMS = Get-VM | Where {$_.PowerState -eq "PoweredOn"} |Sort Name
ForEach ($VM in $VMS)
# Process only Windows Server VM’s
   if ($VM.Guest.OSFullName -match "Microsoft Windows*")
# Do a WMI Query
       $results = get-wmiobject -class "Win32_DiskPartition" -namespace "root\CIMV2" -ComputerName $VM

           foreach ($objItem in $results)
# Do the match
               if ($objItem.StartingOffset -match $StartingOffset){
write-host $objItem.SystemName
write-host $objItem.Name
write-host "Partition aligned" -foregroundcolor green
write-host $objItem.SystemName
write-host $objItem.Name
write-host "Partition NOT aligned" -foregroundcolor red
# Disconnect from vCenter
Disconnect-VIServer -Confirm:$False

after running the script, the following output will be generated:



5 thoughts on “Powershell: Check if partition is aligned or not

  1. Nice script. Am getting a “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)” attempting to run however. during the WMI query..

    1. I’m getting similar

      Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x80070
      At C:\Test.ps1:15 char:21
      + $wmi = get-wmiobject <<<< -class "Win32_DiskPartition" -namespace "root\CIMV
      2" -ComputerName $vm
      + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMExcept
      + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands

  2. Funny, i was writing a very similar script and troubleshooting out he RPC server issue when I ran into this. Would’ve saved me a bit of time! I like it.
    I am writing mine to be a csv generator for reporting.

    The RPC error issue was in my case resovled by adding the “remote management” check box on the targeted server / desktop if the firewall was anabled or disabling the firewall. (this is in my lab, so limited cases.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.