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}
Try something like this.
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
Try something like this.
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
Hi LucD
Thank you for such a quick reply and helping me out with the Script.
Thanks.
i am trying to run this cmdlet but getting an error. Are you setting any other variables and parameters besides the lines you have ?
What you see if you run the following
$global:defaultviserver
just want to confirm if you are connect to vCenter.