Checking partition alignment with PowerCLI

Posted by Julian on Server Fault See other posts from Server Fault or by Julian
Published on 2013-10-24T18:25:54Z Indexed on 2013/10/28 21:56 UTC
Read the original article Hit count: 256

I'm trying to verify that the file system partitions within each of the servers I'm working on are aligned correctly. I've got the following script that when I've tried running will either claim that all virtual servers are aligned or not aligned based on which if statement I use (one is commented out):

$myArr = @()
$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 ($partition in $wmi){
        $Details = "" | Select-Object VMName, Partition, Status
        #if (($partition.startingoffset % 65536) -isnot [decimal]){
        if ($partition.startingoffSet -eq "65536"){
            $Details.VMName = $partition.SystemName
            $Details.Partition = $partition.Name
            $Details.Status = "Partition aligned"
        }
        else{
            $Details.VMName = $partition.SystemName
            $Details.Partition = $partition.Name
            $Details.Status = "Partition not aligned"
        }
    $myArr += $Details
    }
}
$myArr | Export-CSV -NoTypeInformation "C:\users\myself\Documents\Scripts\PartitionAlignment.csv"

Would anyone know what is wrong with my code? I'm still learning about partitions so I'm not sure how I need to check the starting off-set number to verify alignment.

EDIT:

    $myArr = @()
    $vms = get-vm | where {$_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -match "Microsoft Windows*" } | sort name
    $wmi = get-wmiobject -class "win32_DiskPartition" -namespace "root\CIMV2" -ComputerName $vm
    #foreach ($_ In Get-WMIObject Win32_DiskPartition | Select Name, BlockSize, NumberOfBlocks, StartingOffSet, @{n='Alignment'; e={$_.StartingOffSet/$_.BlockSize}}) {$_}
    foreach ($wmi| Select Name, BlockSize, NumberOfBlocks, StartingOffSet, @{n='Alignment'; e={$_.StartingOffSet/$_.BlockSize}}) {$_}

© Server Fault or respective owner

Related posts about vmware-esxi

Related posts about powershell