With PowerCLI it is very easy to get a list of provisioned storage for a list of VMs:
Get-VM | Select-Object Name,@{n="ProvisionedGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}
You can combine this with other cmdlets to limit the search to a specific folder, datastore, etc...
To get a complete sum of all the VMs, add | Measure-Object -Sum ProvisionedGB at the end.
If the webclient is letting you down, you can also use PowerCLI to expand datastores.
First, as usual, expand the volume on the storage level. Then, fire up PowerCLI, log on to the vCenter/host and run the following script, replacing the name of the datastore you wish to expand:
$name = 'Datastore1' $datastore = Get-Datastore $name $esxi = Get-View -Id ($Datastore.ExtensionData.Host | Select -Last 1 | Select -ExpandProperty Key) $datastoreSystem = Get-View -Id $esxi.ConfigManager.DatastoreSystem $expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef) $datastoreSystem.ExpandVmfsDatastore($datastore.ExtensionData.MoRef,$expandOptions.spec)
Sometimes, you need to temporarily start a service (such as SSH) to perform some maintenance task. PowerCLI can help you with this:
To start the SSH server on each host of a vCenter:
Get-VMHost | Get-VMHostService | ? {$_.Key -eq "TSM-SSH"} | Start-VMHostService
To stop the SSH server:
Get-VMHost | Get-VMHostService | ? {$_.Key -eq "TSM-SSH"} | Stop-VMHostService -Confirm:$false
As always, you can make adjustments to the oneliner to select another service to start/stop, or further limit the selection of hosts to a cluster or a group of hosts (e.g. filtered by name).
I wrote a script to list virtual disk information for a specified VM, including VMDK path, SCSI IDs and more. It is loosely based on this script but excludes all WMI info.
With PowerCLI, you can generate all sorts of lists. To retrieve the configured and reported OS version of your VMs, try running this one-liner:
Get-VM | Sort | Get-View -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName", "Guest.IpAddress") | Select -Property Name, @{N="Configured OS";E={$_.Config.GuestFullName}}, @{N="Running OS";E={$_.Guest.GuestFullName}}, @{N="IP Address";E={@($_.Guest.IpAddress)}} | Export-CSV -Delimiter ";" -Path "vms.csv"
You can quickly get a list of VMs, the datastores they are using and the logical folder they are in through PowerCLI:
Get-VM | Select Name,@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},@{N="Folder";E={$_.Folder.Name}}
Combine it with Export-CSV to export the results to a CSV file.
Occassionally, it may be necessary to perform disk consolidation. If you have a lot of VMs which need consolidation, it can be tedious to do this in the webclient. Fortunately, it's also possible to mass-consolidate via PowerCLI.
Install and log in using PowerCLI.
To show which VM's need consolidation, run:
Get-VM | ? {$_.Extensiondata.Runtime.ConsolidationNeeded}
To actually perform disk consolidation, run:
Get-VM | ? {$_.Extensiondata.Runtime.ConsolidationNeeded} | % {$_.ExtensionData.ConsolidateVMDisks_Task()}
« ‹ | October 2024 | › » | ||||
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |