VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get-VM Datastore Info

Hi,

I am trying to get the VMs and its Datastore Info but I would like to exclude from particular VMs, which is not working using below. The exclude Datastore option is not working.

Please help!!

Get-Folder "Finance" | Get-VM | where {$_.Datastore.Name -ne "MyDS*"} | Select Name, Datastore

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The meta character * only works with the -like or -notlike operator, not the -ne operator.
Also, the VirtualMachine object does not have a property Datastore.
You could do

 

Get-Folder "Finance" | 
Get-VM -PipelineVariable vm | 
Get-Datastore | where{$_.Name -notlike "MyDS*"} | 
select @{N='VM';E={$vm.Name}},@{N='Datastore';E={$_.Name}}

 

 


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The meta character * only works with the -like or -notlike operator, not the -ne operator.
Also, the VirtualMachine object does not have a property Datastore.
You could do

 

Get-Folder "Finance" | 
Get-VM -PipelineVariable vm | 
Get-Datastore | where{$_.Name -notlike "MyDS*"} | 
select @{N='VM';E={$vm.Name}},@{N='Datastore';E={$_.Name}}

 

 


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much LucD. that worked perfectly 🙂

 

0 Kudos