VMware Cloud Community
Nordvs
Contributor
Contributor
Jump to solution

VM + DataStore + DS Capacity + DS Free space

I was looking for a hint to get a quick view of VMs with their Datastore(s) details. For example I have list of VMs in a .csv file so I want to get view like that: VM+ datatores + capacity + free space

But so far I can only get VM + Datastore

$vmList=Get-Content "C:\Temp\VMs.csv"

$AllVMs = Get-VM $vmList

$MultVM=ForEach ($VM in $AllVMs){ Get-View  -ViewType VirtualMachine -filter @{"Name"="$VM"} -Property "Name", "Config.DatastoreUrl"}

$MultVM | Select-Object -Property Name, @{N="DataStore";E={$_.Config.DatastoreUrl | %{$_.Name}}}

Name                        DataStore

----                           ---------

vm01                    Datastore-LUN03

vm02                    Datastore-LUN07

vm03                    Datastore-LUN08

Thanks.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vmList=Get-Content "C:\Temp\VMs.csv"

$filter = ($vmList) -join '|'

$props = 'Name','Storage.PerDatastoreUsage'

foreach($vm in (Get-View  -ViewType VirtualMachine -filter @{"Name"=$filter} -Property $props)){

        $vm.Storage.PerDatastoreUsage |

        Select @{N='VM';E={$vm.Name}},

            @{N='Datastore';E={($script:ds = Get-View -Id $_.Datastore -Property Name,Summary).Name}},

            @{N='DSCapacityGB';E={[math]::Round($script:ds.Summary.Capacity/1GB)}},

            @{N='DSFreeGB';E={[math]::Round($script:ds.Summary.FreeSpace/1GB)}},

            @{N='DSUsedForVMGB';E={[math]::Round($_.Committed/1GB)}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

11 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vmList=Get-Content "C:\Temp\VMs.csv"

$filter = ($vmList) -join '|'

$props = 'Name','Storage.PerDatastoreUsage'

foreach($vm in (Get-View  -ViewType VirtualMachine -filter @{"Name"=$filter} -Property $props)){

        $vm.Storage.PerDatastoreUsage |

        Select @{N='VM';E={$vm.Name}},

            @{N='Datastore';E={($script:ds = Get-View -Id $_.Datastore -Property Name,Summary).Name}},

            @{N='DSCapacityGB';E={[math]::Round($script:ds.Summary.Capacity/1GB)}},

            @{N='DSFreeGB';E={[math]::Round($script:ds.Summary.FreeSpace/1GB)}},

            @{N='DSUsedForVMGB';E={[math]::Round($_.Committed/1GB)}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Nordvs
Contributor
Contributor
Jump to solution

That simple! This is amazing! Thank you sir!

0 Kudos
Nordvs
Contributor
Contributor
Jump to solution

One more thing, it is showing only where VMX file located, what if VM has disks located on multiple datastores?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The PerDatastoreUsage  property has entries for each datastore where the VMhas files.

So they should all show.

Did you see the contrary?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nordvs
Contributor
Contributor
Jump to solution

Not showing the second disk. Here is what I see with old script :

Name                           Value

----                           -----

tic-vm01                  {Datastore-LUN03, Datastore-LUN07}

tic-vm02                  Datastore-LUN08

tic-vm03                  Datastore-LUN08

And this is with new:

VM            : tic-vm01

Datastore     : Datastore-LUN03

DSCapacityGB  : 4096

DSFreeGB      : 2052

DSUsedForVMGB : 104

VM            : tic-vm02

Datastore     : Datastore-LUN08

DSCapacityGB  : 4096

DSFreeGB      : 3249

DSUsedForVMGB : 423

VM            : tic-vm03

Datastore     : Datastore-LUN08

DSCapacityGB  : 4096

DSFreeGB      : 3249

DSUsedForVMGB : 423

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Seems to be working for me, are you sure you are running the script exactly as I posted above?

Don't mind the numbers, these are Thin provisioned HD

hd.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nordvs
Contributor
Contributor
Jump to solution

I do not get, it works for one VC but not for another one. It is very strange -same version, same build number O_O

I will try on another 2 VCs

0 Kudos
Nordvs
Contributor
Contributor
Jump to solution

It seems like only works for one VC out 4. For 3d one it returns 4th VM that is not even in the file. For first VM it is not showing second disk. It is really wired

0 Kudos
Nordvs
Contributor
Contributor
Jump to solution

I figured out the issue. It looks like a PCLI v.6.5.1 issue (bug?), I did update it to 6.5.4 and now it is showing all disks. But for one VC I see an extra VM. I suspect it is because the VM was renamed and initially had same name as another one in the list. Anyway thanks again for the help! You are the best!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks.

You sure that VM is not a Templae?

With Get-View -ViewType VirtualMachine you also get the Templates.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nordvs
Contributor
Contributor
Jump to solution

It is a VM (| Where {-not $_.Config.Template}),  but it is not that big issue, in this case more information  is better than less Smiley Wink

Thanks again!

0 Kudos