VMware Cloud Community
namerg
Contributor
Contributor
Jump to solution

List all VMs per Datastore

Hello,

At some point LucD posted the following answer in another thread http://communities.vmware.com/thread/293395

Get-Datacenter | Get-VM | %{$vm = $_Get-Datastore -VM $vm | %{$vm.Name + "-" + $_.Name} } | ft -AutoSize

But on my end, I can not make it work I get the following error:

You must provide a value expression on the right-hand side of the '-' operator.
At line:1 char:41
+ Get-Datacenter | Get-VM | %{$vm = $_Get- <<<< Datastore -VM $vm | %{$vm.Name + "-" + $_.Name} } | ft -AutoSize
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

Thanks for your help,


1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

There is a semicolon missing. It should be:

Get-Datacenter | Get-VM | %{$vm = $_ ; Get-Datastore -VM $vm | %{$vm.Name + "-" + $_.Name} } | ft -AutoSize

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

There is a semicolon missing. It should be:

Get-Datacenter | Get-VM | %{$vm = $_ ; Get-Datastore -VM $vm | %{$vm.Name + "-" + $_.Name} } | ft -AutoSize

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
namerg
Contributor
Contributor
Jump to solution

Thank you man, you guys rock.