title: How to retrieve the name and path of VM's through powercli
body: <p>am using the below script to retrieve the <strong>NAME and PATH</strong> of the VM's and in the <strong>PATH</strong> am getting the full length path which i dont want it, i just need the path which is displaying after the <strong>Resources</strong> in the output</p>
  
  <p>here is my code:</p>
  
  <pre><code> function Get-Path{
          param($Object)
  
          $path = $object.Name
          $parent = Get-View $Object.ExtensionData.ResourcePool
          while($parent){
              $path = $parent.Name + "/" + $path
              if($parent.Parent){
                  $parent = Get-View $parent.Parent
              }
              else{$parent = $null}
          }
          $path
      }
  
      Get-VM | Select Name,
          @{N="Path";E={Get-Path -Object $_}}
  </code></pre>
  
  <blockquote>
    <p>Output:</p>
  </blockquote>
  
  <p><em>Name:</em></p>
  
  <pre><code>AWServer 3.1
  CCW%.1.1_DEMO
  DEMO-EA
  MUSE_DEMO
  UV_CARDIO
  UView-Web_Cardio-2015-v2
  </code></pre>
  
  <p><em>PATH:</em></p>
  
  <pre><code>&gt; ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/vbnrt735w6%5c/sdfasd34564/AWServer
  &gt; 3.1  ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/CCW5.1.1_DEMO
  &gt; ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/4564/DEMO-EA
  &gt; ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/vbnrt735w6%5c/MUSE_DEMO
  &gt; ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/asd/UV_CARDIO
  &gt; ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/UView-Web_Cardio_2015_v2
  </code></pre>