VMware Cloud Community
justinsmith
Enthusiast
Enthusiast
Jump to solution

Misaligned VMDK's Powercli Script Help

I have a script that I run against a vCenter server. Basically finds all vm's in vCenter and ruins a get-wmiobject command against them to get the VMNAME, Partition, Offset and Status and exports it to excel.

Here's a sample output of the data that gets exported to excel:

VMNamePartitionOffsetStatus
pdxvvmdb1Disk #0, Partition #18193150KBPartition NOT aligned
pdxvvmdb1Disk #0, Partition #18193150KBPartition NOT aligned

My "problem" is its not giving me the correct partition info in excel (via system info), see below.

It only has 1 vmdk with 2 partitions, so it should output both partition 1 and 2 and the offsets, since they're both incorrect?

Also looking to add a line to the script to add the datastore and the vmdk file location ([PDXESX1_RAID] pdxvvmdb1/pdxvvmdb1.vmdk) in this case and have that output to the excel. Possible?

I attached the script since its pretty long....

0 Kudos
22 Replies
justinsmith
Enthusiast
Enthusiast
Jump to solution

I thought so, but I've never had to do 2 calls in a powercli script... Ill play around with it and see if I can get it to work.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can't you just do

$wmiOS = get-wmiobject -class "Win32_OperatingSystem" -namespace "root\CIMV2" -ComputerName $vm -ErrorAction silentlycontinue           
$wmiPart = get-wmiobject -class "Win32_DiskPartition" -namespace "root\CIMV2" -ComputerName $vm -ErrorAction silentlycontinue           
foreach ($objItem in $wmiPart){ # Loop through the partitions
....
   $wmiOS.Caption # Reference the OS class
....
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

justinsmith
Enthusiast
Enthusiast
Jump to solution

Of course I can  Smiley Happy

I had to change a couple things and remove the loop so it wouldnt output the contents in the powercli screen.

When I tried it on my own I had line below incorrect:

Correct:

foreach ($objItem in $wmiPart)

Incorrect:

foreach ($objItem in $wmiOS)

Amazing what I've learned. Thanks again!

0 Kudos