I need to move a large number of VM's with MS Server 2008 to another storage.
Could somebody provide me a small script to get a list about: all VM's with GuestOS Type (MS Server 2008 filtered), Datastore name and VM's overall size!
Thanks in advance
Hello, farkasharry-
How about something like:
Get-View -ViewType VirtualMachine -Property Name,Config.GuestFullName,Storage.PerDatastoreUsage,Summary.Storage -Filter @{"Config.GuestFullName" = "Windows.*2008.*"} | %{
## get the name(s) of the datastores on which this VM resides
$strDatastoreNames = ($_.Storage.PerDatastoreUsage | %{Get-View -Id $_.Datastore -Property Name} | %{$_.Name}) -join ","
New-Object -TypeName PSObject -Property @{
Name = $_.Name
GuestOS = $_.Config.GuestFullName
"Datastore(s)" = $strDatastoreNames
## the amount of storage that the VM is using
UsedGB = [Math]::Round($_.Summary.Storage.Committed / 1GB, 1)
## the total amount of storage that the VM _could_ use
ProvisionedGB = [Math]::Round(($_.Summary.Storage.Committed + $_.Summary.Storage.Unommitted) / 1GB, 1)
} ## end new-object
} | Select Name, GuestOS, "Datastore(s)", UsedGB, ProvisionedGB
This filters on VMs with an OS name ("GuestFullName") that matches "Windows.*2008.*", and returns their name, the GuestFullName, the datastore(s) on which they reside (possibly more than one), and the used- and provisioned disk space in GB.
The return items are objects, so you can format/select/export the info as you please, using, say, Format-Table, Select-Object, Export-Csv, etc.
And, since it uses the Get-View cmdlet, it should run pretty quickly.
How does that do for you?
Here is a script that can get you at least started. It lists VMs with Name and Disk sizes. You will need to modify it to gather the other information you need.
http://vsential.com/?attachment_id=273
Hello, farkasharry-
How about something like:
Get-View -ViewType VirtualMachine -Property Name,Config.GuestFullName,Storage.PerDatastoreUsage,Summary.Storage -Filter @{"Config.GuestFullName" = "Windows.*2008.*"} | %{
## get the name(s) of the datastores on which this VM resides
$strDatastoreNames = ($_.Storage.PerDatastoreUsage | %{Get-View -Id $_.Datastore -Property Name} | %{$_.Name}) -join ","
New-Object -TypeName PSObject -Property @{
Name = $_.Name
GuestOS = $_.Config.GuestFullName
"Datastore(s)" = $strDatastoreNames
## the amount of storage that the VM is using
UsedGB = [Math]::Round($_.Summary.Storage.Committed / 1GB, 1)
## the total amount of storage that the VM _could_ use
ProvisionedGB = [Math]::Round(($_.Summary.Storage.Committed + $_.Summary.Storage.Unommitted) / 1GB, 1)
} ## end new-object
} | Select Name, GuestOS, "Datastore(s)", UsedGB, ProvisionedGB
This filters on VMs with an OS name ("GuestFullName") that matches "Windows.*2008.*", and returns their name, the GuestFullName, the datastore(s) on which they reside (possibly more than one), and the used- and provisioned disk space in GB.
The return items are objects, so you can format/select/export the info as you please, using, say, Format-Table, Select-Object, Export-Csv, etc.
And, since it uses the Get-View cmdlet, it should run pretty quickly.
How does that do for you?
Wow, thanks Matt!
It works like a charm! The only thing missing to my happiness is a line to count the machines, and a Filter for different datastores.
But the correct answer and the points have been definetly earned by you!
Thanks a lot