VMware Cloud Community
virtualdive
VMware Employee
VMware Employee
Jump to solution

Template Location - PowerCLI

Hello,

Is there any powercli script that can generate the list of templates and their Datastore name where they are residing? I only need these two properties.

Thank you,

Regards,

'V'
thevshish.blogspot.in
vExpert-2014-2021
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Template |
Select Name,@{N="Datastore";E={[string]::Join(',',(Get-View $_.DatastoreIdList | %{$_.Name}))}}


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

View solution in original post

0 Kudos
6 Replies
MKguy
Virtuoso
Virtuoso
Jump to solution

The following snippet will list all templates and their datastores:

Get-Template | Select -Property Name, @{N="Datastore";E={(Get-Datastore -Id $_.DatastoreIdList).Name}} | FT -autosize

Name                    Datastore

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

Template_1          Datastore5

Template_2          Datastore5

Template_3          Datastore6

[...]

-- http://alpacapowered.wordpress.com
virtualdive
VMware Employee
VMware Employee
Jump to solution

thanks MKguy,

This script ran fine but unfortunately it did not give the Datastore names. It only gave the Template names.

something missing?

thanks again,

Regards,

'V'
thevshish.blogspot.in
vExpert-2014-2021
0 Kudos
MKguy
Virtuoso
Virtuoso
Jump to solution

Which PowerCLI version are you running? I have no problem getting the Datastore names with the latest version 5.1 R2:

https://my.vmware.com/group/vmware/get-download?downloadGroup=VSPS510-PCLI-510R2

Get-PowerCLIVersion

PowerCLI Version

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

   VMware vSphere PowerCLI 5.1 Release 2 build 1012425

-- http://alpacapowered.wordpress.com
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Template |
Select Name,@{N="Datastore";E={[string]::Join(',',(Get-View $_.DatastoreIdList | %{$_.Name}))}}


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

0 Kudos
virtualdive
VMware Employee
VMware Employee
Jump to solution

Hi MKGuy,

I am using PowerCLI 4.1

Hi Luc

As always .. you are the Man! Smiley Happy your one liner worked perfect. thank you and full marks.

Regards,

'V'
thevshish.blogspot.in
vExpert-2014-2021
MKguy
Virtuoso
Virtuoso
Jump to solution

Cool if it works with Lucs script. Just one thing to note: You can use the latest PowerCLI even with 4.x based vCenter/ESXi servers, so there isn't really any reason to not upgrade considering PowerCLI 5.1 R2 contains goodies like dvSwitch and Powershell 3.0 support.

http://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/powercli51r2-releasenotes.html

VMware vSphere PowerCLI 5.1 Release 2 supports the following VMware environments:

  • vCenter Server 5.1.0a
  • VMware ESXi 5.1.0a
  • vCenter Server 5.0 Update 2
  • VMware ESXi 5.0 Update 2
  • vCenter Server 4.1 Update 3
  • VMware ESXi 4.1 Update 3
  • VMware ESX 4.1 Update 3
  • vCenter Server 4.0 Update 4
  • VMware ESX 4.0 Update 4
  • VMware ESX 4.0i Update 4
-- http://alpacapowered.wordpress.com
0 Kudos