VMware Cloud Community
itsvivekg
Contributor
Contributor
Jump to solution

To Check if a virtual object is VM or template

I need to check for a list of VMs\Templates, which ones are templates. Is there a way to do that - powercli way?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

An alternative

$names = Get-Content names.txt

$namesRegEx = $names -Join '|'

Get-View -ViewType VirtualMachine -Filter @{"Name"=$namesRegEx} |

Select Name,@{N="Template";E={$_.Config.Template}}


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

View solution in original post

8 Replies
LucD
Leadership
Leadership
Jump to solution

There are 2 cmdlets, Get-VM and Get-Template.

If you suppress the errors you could use those. For example

$names = Get-Content names.txt

$vms = Get-VM -Name $names -ErrorAction SIlentlyContinue

$templates = Get-Template -Name $names -ErrorAction SilentlyContinue

Or do you mean something else ?


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

LucD
Leadership
Leadership
Jump to solution

An alternative

$names = Get-Content names.txt

$namesRegEx = $names -Join '|'

Get-View -ViewType VirtualMachine -Filter @{"Name"=$namesRegEx} |

Select Name,@{N="Template";E={$_.Config.Template}}


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

itsvivekg
Contributor
Contributor
Jump to solution

I am using this, but its not helping -

$TEMPLATE = (get-Template $VM_NAME).Name

If ($TEMPLATE -eq $VM_Name)

{$CHK = "TEMPLATE"}

One more thing, When I m taking $cells.item($i,8)  = (Get-VM $INPUT_IP|Select PowerState) , its thowing "0" for Powered OFF VMs.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try any of the 2 sample script I gave ?


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

Reply
0 Kudos
itsvivekg
Contributor
Contributor
Jump to solution

I havent tried it yet.But I need something to check one server one time.

Can you convert this for my need -

Get-View -ViewType VirtualMachine -Property Name -Filter @{"Config.Template" = "true"}

LucD
Leadership
Leadership
Jump to solution

Not sure waht you mean with "one server", is that 1 vCenter or 1 ESXi server ?


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

Reply
0 Kudos
itsvivekg
Contributor
Contributor
Jump to solution

One VM\template at a time.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid I still don't get what exactly you want here.

Do you want to enter a name and then check if it's a VM or a template ?


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

Reply
0 Kudos