
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}
else{
write-host $objItem.SystemName
write-host $objItem.Name
write-host "Partition NOT aligned" -foregroundcolor red
write-host
}
}
}
}
# Disconnect from vCenter
Disconnect-VIServer -Confirm:$False
after running the script, the following output will be generated:
