VMware Cloud Community
Daithi_N
Enthusiast
Enthusiast
Jump to solution

Get Template UUID & Absolute Folder Path.

Hi,

Within our environment, we may have duplicated Templates within Different Locations / Datacenters within vCenter:

I am looking at a way of getting the absolute folder path along with UUID for each Template

Example:

UUID                                        Folder

---------                                   ---------------

6b500805b55f                      DC-Test/vm/templates/

6b500805b54                     DC-Test1/vm/templates/

$vCenter_Servers = ${env:vcenter}

$user = ${env:user}

$pswd = ${env:password}

$Template = ${env:template}

Connect-VIServer -Server $vCenter_Servers -User $user -Password $pswd

Get-Template $Template | %{(Get-View $_.Id).config}

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this.

Get-Template |

Select Name,

    @{N='UUID';E={$_.ExtensionData.Config.Uuid}},

    @{N='Path';E={

        $templatePath = @()

        $parent = Get-View -Id $_.ExtensionData.Parent

        do{

            $templatePath += $parent.Name

            $parent = Get-View -Id $parent.Parent -ErrorAction SilentlyContinue

        } until($parent.Parent -eq $null)

        [array]::Reverse($templatePath)

        $templatePath -join '/'

    }}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this.

Get-Template |

Select Name,

    @{N='UUID';E={$_.ExtensionData.Config.Uuid}},

    @{N='Path';E={

        $templatePath = @()

        $parent = Get-View -Id $_.ExtensionData.Parent

        do{

            $templatePath += $parent.Name

            $parent = Get-View -Id $parent.Parent -ErrorAction SilentlyContinue

        } until($parent.Parent -eq $null)

        [array]::Reverse($templatePath)

        $templatePath -join '/'

    }}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Daithi_N
Enthusiast
Enthusiast
Jump to solution

Hi LucD

Thank you for such a quick reply and helping me out with the Script.

Thanks.

Reply
0 Kudos
patilp08
Contributor
Contributor
Jump to solution

i am trying to run this cmdlet but getting an error. Are you setting any other variables and parameters besides the lines you have ?

Reply
0 Kudos
wetnose88
Enthusiast
Enthusiast
Jump to solution

What you see if you run the following

$global:defaultviserver

just want to confirm if you are connect to vCenter.

Reply
0 Kudos