Hi
The following script works good except it doesn't show VM with more than one datastore:
Get-VM | Select Name,PowerState, @{N="SnapName";E={
($_ | Get-Snapshot).Name}},@{N="Datastore";E={
($_ | Get-Datastore).Name}},@{ N="TotalDisk"; E={
($_ | Get-harddisk | measure-object -property CapacityGB
-sum).Sum}},@{N="GuestOS";E={
($_ | Get-VMGuest).OSFullName}},@{N="Cluster";E={
($_ | Get-Cluster).Name}}
How can it be modified to list VM with more than one DS?
Thanks
Hello, AGFlora-
You can change the calculated property for the Datastore property to be like:
@{N="Datastore";E={($_ | Get-Datastore | %{$_.Name}) -join ","}}
This will make a comma-separated list of datastores names on which the VM and its disks reside, and should work for VMs that reside on any number of datastores. That do it for you?
Hello, AGFlora-
You can change the calculated property for the Datastore property to be like:
@{N="Datastore";E={($_ | Get-Datastore | %{$_.Name}) -join ","}}
This will make a comma-separated list of datastores names on which the VM and its disks reside, and should work for VMs that reside on any number of datastores. That do it for you?
Hi Matt
Yes this works for me thanks.
I tried this but it didn't work {string]::join ','}). I guess I was close.
Hello-
Hmm. Using the Join() method of the .NET String class should also work. Like:
@{N="Datastore";E={[string]::join(",", ($_ | Get-Datastore).Name)}}
Does that not get it, too?
Yes it does.
Thanks again
Where would I add a filter for example:
Where-Object {$_.Name -like "Datastore*"}
Hello-
Well, depending on your desired outcome -- if you wanted all VMs and to only display datastore names for certain datastores, you would put such a filter inside of the calculated property for Datastore.
More likely, I would think, is that you are wanting to just get info about VMs that are on given datastores. If that is the case, you can do the filtering by just getting the desired datastore(s) first, and then get the VMs that reside on them and do the Select-Object statement that you already have built. So, for this, you would just put a Get-Datastore call at the start with the given datastore(s) name wildcard, and then pipe that to the rest of what you already have, like:
Get-Datastore -Name myDatastores* | Get-VM | Select ...
How about that?
Exactly what I was looking for...
Thanks!