VMware PowerShell Get-VIHumanReadablePath

An example of how to get the human readable path of an object in the VMware SDK. This is using PowerShell and requires that PowerCLI be installed, but should be easily converted to other languages.

Function Get-VIHumanReadablePath
{
    param
    (
        $target
    )
 
    try
    {
        if ($target.GetType().BaseType -ne [VMware.Vim.ManagedEntity])
        {
            $target = $target | Get-View -ErrorAction SilentlyContinue
        }
    }
    catch
    {
        $target = $null
    }
 
    if (!$target)
    {
        throw "Get-VIHumanReadablePath: Could not get the Managed Entity representation of -target"
    }
 
    $path = $target.Name
    while ($target.Parent)
    {
        $target = Get-View $target.Parent  
        $path = $target.Name + "/" + $path           
    }
 
    $path
}

Example usage

Get-VIHumanReadablePath (Get-Folder Linux)
Get-VIHumanReadablePath (Get-VM LinuxTemp01)
Get-VIHumanReadablePath (Get-VM LinuxTemp01 | Get-View)
Get-VIHumanReadablePath (Get-ResourcePool Prod)
Get-VIHumanReadablePath (Get-VM LinuxTemp01 | Get-ResourcePool)
Get-VIHumanReadablePath (Get-VMHost esx001.local)

Comment (1)

  1. Pingback: Site Recovery Manager configuration export with SRM API 5.0 « wolowicz.info

Leave a Comment

Your email address will not be published.