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

by Grzegorz Kulikowski

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.
[sourcecode language=”powershell”]
get-template vm2
—–
Name Id
—- —
vm2 VirtualMachine-vm-738
[/sourcecode]
Is this all ? Let’s see what else can we see using this view id
[sourcecode language=”powershell”]
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
[/sourcecode]
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:
[sourcecode language=”powershell”]
$templateview=get-view -id (get-template vm1).id
($templateview.config.hardware.device | ? {$_ -is [vmware.vim.VirtualVmxnet]})|%{$_.DeviceInfo}
——–
Label Summary
—– ——-
Network adapter 1 VM Network
[/sourcecode]
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
[sourcecode language=”powershell”]
($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
[/sourcecode]
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:
[sourcecode language=”powershell”]
($templateview.config.hardware.device | ? {$_ -is [vmware.vim.VirtualFloppy]})|%{$_.DeviceInfo}
——–
Label Summary
—– ——-
Floppy drive 1 Remote
Floppy drive 2 Remote
[/sourcecode]
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
[sourcecode language=”powershell”]
$templateview.ResourceConfig.MemoryAllocation
———-
Reservation : 100
ExpandableReservation : False
Limit : -1
Shares : VMware.Vim.SharesInfo
[/sourcecode]
Well it seems that my template has 100 mb memory reserved, and no limit set. You can query cpu allocation as well:
[sourcecode language=”powershell”]
$templateview.ResourceConfig.CpuAllocation
———-
Reservation : 0
ExpandableReservation : False
Limit : -1
Shares : VMware.Vim.SharesInfo
[/sourcecode]
What tools upgrade policy will my vms have after deployment ? We can also check this :
[sourcecode language=”powershell”]
$templateview.config.tools.ToolsUpgradePolicy
———-
upgradeAtPowerCycle
[/sourcecode]
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 😉

You may also like

2 comments

Anonymous November 20, 2012 - 6:20 pm

what if i wanted to view number of cpus and totalmemory?

Reply
psvmware November 20, 2012 - 7:00 pm

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

Reply

Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish