I am working on automating a capacity planning spreadsheet. I have the below script to pull VM information and export it to a CSV. I've been playing around with it to try to get different output formatting, but I haven't been able to get it to work right.
First, a VM with multiple harddisks on the same datastore should just show the total provisioned and total used space, not create a new line for each disk.
Second, a VM with multiple harddisks on different datastores should show each datastore on its own line with its own total provisioned and used space for that VM.
CPU and Memory should only be listed on the first line for any VM.
Can anyone tell why the Get-Datacenter loop only loops through the first Datacenter? I'm using PowerGUI and stepping through the code and it drops into the ForEach loop, and even going to a PowerCLI command line returns multiple Datacenters. It will loop through the multiple Clusters in the Datacenter, but then drops out.
I think I need to move the For loop for the Get-HardDisk further down to just before the Datastore element. However, when I do, the datastore gets listed as either blank or Hard disk #, with no sizes for provisioned or used (columns are not even there).
I've attached 2 versions of the script, one that gives all the information that I'm looking for, but includes the CPU and Memory for a VM on multiple lines for each disk. The 2nd has the Get-HardDisk loop moved to where I think it belongs.
I'm fairly inexperienced with scripting. I'm sure I'm missing a basic component or due to copy and paste, have included something I shouldn't have. I just can't see it.
Thank you in advance for any assistance!