How to check template settings without converting it to vm using get-teamplate and get-view?


So if we will look at a template vm using vSphere client we can’t see more than basic settings. We can check the guest OS, vm version, cpu, memory, vmware tools status, state, on which host was it registered, and on which datastore it resides. That’s it.
Ok, so in order to get some more information from template we can use get-view.

get-template vm2
-----
Name                Id
----                --
vm2            VirtualMachine-vm-738

Is this all ? Let’s see what else can we see using this view id

get-view -id (get-template vm2).id
-------
Capability           : VMware.Vim.VirtualMachineCapability
Config               : VMware.Vim.VirtualMachineConfigInfo
Layout               : VMware.Vim.VirtualMachineFileLayout
LayoutEx             : VMware.Vim.VirtualMachineFileLayoutEx
Storage              : VMware.Vim.VirtualMachineStorageInfo
EnvironmentBrowser   :
ResourcePool         :
ParentVApp           :
ResourceConfig       : VMware.Vim.ResourceConfigSpec
Runtime              : VMware.Vim.VirtualMachineRuntimeInfo
Guest                : VMware.Vim.GuestInfo
Summary              : VMware.Vim.VirtualMachineSummary
Datastore            : ...
Network              : {}
Snapshot             :
RootSnapshot         : {}
GuestHeartbeatStatus : gray
LinkedView           :
Parent               : Folder-group-v..0
CustomValue          : {..}
OverallStatus        : green
ConfigStatus         : green
ConfigIssue          : {}
EffectiveRole        : {-1}
Permission           : {}
Name                 : vm2
DisabledMethod       : {MakePrimaryVM_Task, TerminateFaultTol
RecentTask           : {}
DeclaredAlarmState   : {}
TriggeredAlarmState  : {}
AlarmActionsEnabled  : True
Tag                  : {}
Value                : {507}
AvailableField       : {}
MoRef                : VirtualMachine-vm-738
Client               : VMware.Vim.VimClient

So as you can see we can see similar output as if you would apply get-view to normal virtual machine. From here you can query your template just as it would be virtual machine. What is worth mentioning here is that it will be impossible to make any tasks on the template, but still we can get information.
So let’s check for example what network interfaces our templates has:

$templateview=get-view -id (get-template vm1).id
($templateview.config.hardware.device | ? {$_ -is [vmware.vim.VirtualVmxnet]})|%{$_.DeviceInfo}
--------
Label                      Summary
-----                      -------
Network adapter 1          VM Network

So we can see that we have 1 network adapter which is connected to ‘VM Network’ portgroup.
Now let’s see how were the disks configured

($templateview.config.hardware.device | ? {$_ -is [vmware.vim.VirtualDisk]})|%{$_.DeviceInfo}
---------
Label                         Summary
-----                         -------
Hard disk 1                   1,048,576 KB
Hard disk 2                   1,048,576 KB

Now again, we create some templates and we try to remind “have i put this floppy device or not ?” So normally you would have to mark template as a vm, then edit settings and so on..
Let’s check if i have put floppy to template:

($templateview.config.hardware.device | ? {$_ -is [vmware.vim.VirtualFloppy]})|%{$_.DeviceInfo}
--------
Label                                        Summary
-----                                        -------
Floppy drive 1                               Remote
Floppy drive 2                               Remote

Wow! Not one but two! 😉
Ok few times i have seen situation when people were surprised that some of vms have memory reservations/limit on them and they were wondering how ?! “i did not set it up”
Let’s see if we have some memory limits or reservations

$templateview.ResourceConfig.MemoryAllocation
----------
Reservation           : 100
ExpandableReservation : False
Limit                 : -1
Shares                : VMware.Vim.SharesInfo

Well it seems that my template has 100 mb memory reserved, and no limit set. You can query cpu allocation as well:

$templateview.ResourceConfig.CpuAllocation
----------
Reservation           : 0
ExpandableReservation : False
Limit                 : -1
Shares                : VMware.Vim.SharesInfo

What tools upgrade policy will my vms have after deployment ? We can also check this :

$templateview.config.tools.ToolsUpgradePolicy
----------
upgradeAtPowerCycle

Nice… And all this information AND MORE! we can grab without converting template to vm. So if you want really quickly take a look on some specific property of your template , get-view will help you out 😉

Advertisements

2 thoughts on “How to check template settings without converting it to vm using get-teamplate and get-view?

    • That will be : $templateview.summary.config.memorysizeMB for totalmemory and $templateview.summary.config.numcpu for the number of vcpus.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s