2 Replies Latest reply on May 20, 2020 7:22 AM by Daithi_N

    Get Template UUID & Absolute Folder Path.

    Daithi_N Novice

      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. Re: Get Template UUID & Absolute Folder Path.
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Get Template UUID & Absolute Folder Path.
            Daithi_N Novice

            Hi LucD

             

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

             

            Thanks.