VMware PowerCLI

The Best User Interface for your VMware Datacenter!

get-vm has AND and OR operators get getting multiple objects like -location and -datastore

when looking for VMs or other types of objects that are in say a cluster and on a specific datastore in that cluster get-vm -location and  -datastore can return a AND or OR list though AND is likely more helpful most with VMs. 

  • Guest
  • May 9 2019
  • Will not implement
  • Jun 12, 2019

    Admin response

    VMware filters work on an 'and' basis. Luc has given the correct methodology for using PowerShell to do the 'or'.

  • Attach files
  • Luc Dekens commented
    9 May, 2019 08:07pm

    Aren't those basic operations that can easily be done with PowerShell?

    $vmDS = Get-VM -Datastore MyDatastore

    $vmCluster = Get-VM -Location (Get-Cluster -Name MyCluster)

    # Union (OR)
    $vmDS + $vmCluster | Select -Unique

    # Intersection (AND)
    $vmDS | where{$vmCluster.Name -contains $_.Name}