am using the below script to retrieve the NAME and PATH of the VM's and in the PATH am getting the full length path which i dont want it, i just need the path which is displaying after the Resources in the output
here is my 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 $_}}
Output:
Name:
AWServer 3.1
CCW%.1.1_DEMO
DEMO-EA
MUSE_DEMO
UV_CARDIO
UView-Web_Cardio-2015-v2
PATH:
> ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/vbnrt735w6%5c/sdfasd34564/AWServer
> 3.1 ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/CCW5.1.1_DEMO
> ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/4564/DEMO-EA
> ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/vbnrt735w6%5c/MUSE_DEMO
> ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/asd/UV_CARDIO
> ha-folder-root/ha-datacenter/host/tempcardio.centricity.info/Resources/UView-Web_Cardio_2015_v2