Alex Feigenson's Blog Systems Administrator That Communicates Effectively

3May/100

PowerCLI – Windows VM Partition Alignment

In an effort to keep my blog from becoming an wasteland, I bring you a modified version of a script I found here that enumerates virtual machines and then does a WMI call against each one to determine if the partition is aligned.

The original version only does it for one value (65536) - this one does it for both 65536 and 32768.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$myCol = @()
$vms = get-vm | where {$_.PowerState -eq "PoweredOn" -and `
$_.Guest.OSFullName -match "Microsoft Windows*" } | Sort Name
foreach($vm in $vms){
$wmi = get-wmiobject -class "Win32_DiskPartition" `
-namespace "root\CIMV2" -ComputerName $vm            
    foreach ($objItem in $wmi){
        $Details = "" | Select-Object VMName, Partition, Status
            if ($objItem.StartingOffset -eq "65536"){
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition aligned"
            }
            elseif ($objItem.StartingOffset -eq "32768"){
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition aligned"
			}
            else{
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition NOT aligned"
            }
    $myCol += $Details
    }
}
$myCol | Export-Csv -NoTypeInformation "C:\Temp\PartitionAlignment.csv"

There are several things you will need to know about this script prior to running it:

    This requires PowerCLI (from vmware.com).
    Because this script uses WMI, it will use the credentials of the user you are logged in as. You can use something like this if you need to specify credentials.
    If you want to add additional offsets, simply copy the elseif statement and paste it below the } for 32768.

Hope it helps!

VN:F [1.9.12_1141]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.12_1141]
Rating: 0 (from 0 votes)