Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 197835

Re: Misaligned VMDK's Powercli Script Help

$
0
0

I made the same mistake you did in the beginning, the $Details object has to be created at the lowest level.

Like this

 

# Add-PSSnapin vmware.vimautomation.coreconnect-viservervspheredev$myCol=@()$mycol.Initialize()$vms=get-vm|where {$_.PowerState-eq"PoweredOn"-and$_.Guest.OSFullName-match"Microsoft Windows*" } |SortNameforeach($vmin$vms)
{               Try    {        $wmi=get-wmiobject-class"Win32_DiskPartition"-namespace"root\CIMV2"-ComputerName$vm-ErrorActionsilentlycontinue                   foreach ($objItemin$wmi)        {            if ($objItem.StartingOffset%64kb-eq0){                $Details=""|Select-ObjectVMName,Partition,Offset,Status,VMDKPath
               
$Details.VMName=$vm.name
               
$details.VMDKPath=$vm.HardDisks[0].Filename
               
$Details.Partition=$objItem.Name
                $details.offset="$([long]$($objitem.StartingOffset)/1KB)KB"
               
$Details.Status="Partition aligned"                           }            else            {                $Details=""|Select-ObjectVMName,Partition,Offset,Status,VMDKPath
               
$Details.VMName=$vm.name
               
$details.VMDKPath=$vm.HardDisks[0].Filename
                $Details.Partition=$objItem.Name
                $details.offset="$([long]$($objitem.StartingOffset)/1KB)KB"
               
$Details.Status="Partition NOT aligned"                           }            $myCol+=$Details        }   }   catch      {           $Details=""|Select-ObjectVMName,Partition,Offset,Status,VMDKPath
        $Details.VMName=$vm.name
        $details.VMDKPath=""
        $Details.Partition="error"
        $details.offset=""
        $Details.Status="error"
        $myCol+=$Details
    }         }$mycol  |Export-Csv-NoTypeInformation"H:\Excel_Reports\NEW_Production_PartitionAlignment.csv"
#output errors to file$error>>  "c:\temp\partition-check-errors.txt"$error.clear()

 

Note that in the VMDKPath property the script stores the path of the 1st VMDK.


Viewing all articles
Browse latest Browse all 197835

Trending Articles