Hi Folks,
as I´m new to this stuff, I´m wondering if anybody has already done some scripting work to gather a list of all virtual machines, its corresponding datastore(s) and the path to the VMDK-Files (or at least the name of it) - I know this part is already solved - found a couple of them 😉
But my problem is, I need this script drilled down per Cluster or Datacenter. As I said I´m completly new to this CLI-Stuff and don´t have a clue about how to solve this..
Cheers
Markus
I upgraded the PowerCLI on my workstation (Win7/64) to 5.0.1 and got the same error - in attempt to rule out the workstation as a problem, I also installed PowerCLI 5.0.1 on a server (2k3/32) and got the same error as well.
If I remove the Export-CSV related code, the script runs (appears to take time to run, anyway) but has zero output.
Curious...
--- A
Do you get any output when you just display the results on screen ?
ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) { ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) { ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) { ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) { "" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="IP";E={[string]::Join(',',$VM.Guest.IPAddress)}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}} } } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No output at all when run from the server or the 32-bit or 64-bit PowerCLI on my workstation.
--- A
And no error messages ?
Did you try the Get-Datacenter, Get-Cluster and Get-VM cmdlets seperately ?
Do they return anything ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No error message when I run the script without the Export-CSV.
Get-Datacenter produces expected output.
Get-Cluster shows nothing.
Get-VM produces expected output.
--- A
Ok, I think we're getting somewhere.
It looks as if you don't have any clusters in your datacenter(s).
This report will cycle through all the clusters, but since there are none, you will have no results.
You can leave out the Foreach loop for the clusters, then you should be getting the results for each VM in all your datacenters.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you so much!
Got it working - had to pull all references to $Cluster to get it running. Runtime took about 5 minutes, had me worried that things were locked up, but all is well.
Very, very cool...
Thanks again,
--- A
Sorry for bring up such an old post but how do I use this script with import-csv as a input, I have a list of VM's in a CSV file that I want to find the used storage for. (note total storage utilsation not just VMDK sizes)
regards
Tom
The size is returning '0'.
I'll poke around to see what's what...any help would be appreciated.
(the vmdk's return fine - thanks for that...a big help!)
Brilliant script thanks!! Does anyone know how to also list the logical folders that the VM's are in also please?
I am able to use the following in the vCLI;
$VMFolder = "Production"
Get-Folder $VMFolder | Get-VM
This shows me the production folder, but im trying to display all VM's and the folders they reside in, but i dont seem able to run it in the script.
Many thanks
Ian.
An option is to use the New-VIProperty cmdlet.
See the YellowFolderName property on my VIProperties page under VirtualMachine.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello everyone,
I'm having a hard time trying to get this script do what I want it to do.
I'd like to just add a column that shows the provisioned space for each drive. Currently the "VMDK Size" column will show the amount of space actually being used, but would like to output the provisioned size of the drive as well.
I'm a little new at this, I appreciate any help. Any thoughts?
Thanks,
One way of getting the allocated harddisk space is as follows
$vm | Select Name,
@{N="HD Space";E={$_.HardDisks | Measure-Object -Property CapacityGB -Sum | select -ExpandProperty Sum}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the quick reply. So far I am not able to get this added to the script in this thread though. Not sure what I'm doing wrong.
That inner loop goes through all the harddisks.
Do you want the capacity per harddisk or the total for the VM ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
For each VM, idealy, one column would should how how big the hard drive is, and how much space is being used by that drive. E.G.:
VM | Datacenter | Cluster | Hard Disk | Datastore | VMConfigFile | VMDKpath | VMDK Size | Drive Size |
Data1 | DC1 | C1 | Hard disk 1 | DS2 | [DS2] ....vmx | [DS2] ....vmdk | 18.29669 | 40 |
Data1 | DC1 | C1 | Hard disk 2 | SS1 | [SS1] ....vmx | [SS1] ....vmdk | 18.30292 | 60 |
Data2 | DC2 | C2 | Hard disk 1 | SS1 | [SS1] ....vmx | [SS1] ....vmdk | 18.37966 | 40 |
Again, I appreciate your help!
Try something like this
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) { ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) { ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) { ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) { "" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}} } } } } $VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "C:\VmInfo4.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Unfortunately the column still returns blank.
Which PowerCLI version are you using ?
Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference