is it possible to create a script that will display list of available templates (all in “template” folder) and list of all clusters and a list of all datastore that are available to the chosen cluster - so that a remote admin can simply deploy a vm from a template he selected?
You can try this
get-cluster | get-vmhost | Get-Datastore |` select-object Name, @{Name="FreeSpace"; expression={($_ | measure-object -max -property FreeSpaceMB).Maximum}} | ` Sort-Object -property FreeSpace | ` Select-Object -last 1
It will result in 1 object with 2 properties:
- Name: the name of the datastore
- FreeSpace: the amount of freespace
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
http://halr9000.com/article/464#comment-6901
Most definitely.
# list all templates in a single folder get-folder “Templates” | get-template
Datastores are not associated with clusters, they are attached to host servers, so we have to do this:
# list datastores avail to cluster member host server (get-cluster “DRS cluster Foo” | get-vmhost)[0] | get-datastore
The (blah)[0] stuff grabs only the first host server in the cluster. You could pipe get-vmhost to get-datastore, but you’d get duplicate results.
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
thanks, i"m getting closer now
but one Q:
how can I get the datastore name? after running the following command I do get the required result meaning I get the datastore that have the maximum free space in that cluster, BUT i only see the Freespace as a number and I dont see the datastore name that it refers to
get-cluster | get-vmhost | get-datastore | measure-object -max -property FreeSpaceMB
You can try this
get-cluster | get-vmhost | Get-Datastore |` select-object Name, @{Name="FreeSpace"; expression={($_ | measure-object -max -property FreeSpaceMB).Maximum}} | ` Sort-Object -property FreeSpace | ` Select-Object -last 1
It will result in 1 object with 2 properties:
- Name: the name of the datastore
- FreeSpace: the amount of freespace
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks !! working great
how could you write this so you just ended up with just the name of the datastore name rather than
name: datastorename
freespace: freespaceMB
This should do the trick.
get-cluster | get-vmhost | Get-Datastore |` select-object Name | ` Sort-Object -property FreeSpace | ` Select-Object -last 1 |` %{Write-Host $_.Name}
Could probably be done better, PowerShell-wise.
But I leave that to the PS gurus
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Did you mean the vmfs names into a CSV ?
That can be done like this
$report = @() get-cluster | get-vmhost | Get-Datastore |` select-object Name | ` Sort-Object -property FreeSpace | ` Select-Object -last 1 |` %{$row = ""| select Name; $row.Name = $_.Name; $report += $row} $report | Export-Csv "c:\report.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes .. i'm sorry ... when i've realized wich type of question i wrote to u i try to delete it!!! :smileymischief:
luc .. where i can find all object that i need!! in this case i wanna add virtualcenter name ... where i can find this and the other information?