11 Replies Latest reply on Jun 3, 2016 7:06 PM by mattboren

    Folder a VM is in using Get-View


      All, I run a script to gather information about VMs within the environment but have not been able to figure out how to get the folder the VM is in.  I know I could use a get-vm | select Name, Folder etc but the moment I add a get-vm statement I'm going to add a TON of run time to the script.


      I'm currently using this as my get-view command...


      Get-View -ViewType VirtualMachine -Property Name,Runtime.Host,Config.GuestFullName,Config.Annotation,Config.Hardware.NumCPU,Config.Hardware.MemoryMB,Guest.Disk,Config.Template,Guest.IpAddress | Sort-Object -Property Name | %{
      if ($_.Config.Template -ne $true) {
      $row = "" | Select-Object Name,Notes,MemoryGB,Host,CPUs,OS,Cluster,IPAddress,DiskSpaceGB,UsedSpaceGB



      I know I'm just grabbing certain properties but I haven't been able to find the property that gives the Folder name.


      To try and find the right one I've done

      $vm = Get-View -ViewType VirtualMachine -Filter @{"Name"="VM_Name"}


      Then just walked through the variable $vm.(Property)  etc.