itsvivekg
Contributor
Contributor

To Check if a virtual object is VM or template

Jump to solution

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

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

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

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

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.

0 Kudos
LucD
Leadership
Leadership

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


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

0 Kudos
itsvivekg
Contributor
Contributor

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

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

0 Kudos
itsvivekg
Contributor
Contributor

One VM\template at a time.

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos