I have the following script that looks at all VMs in vCenter and emails once a week to list VMs that reside on the standard vSwitch. Per our security group we can't have any production VMs residing on a standard vSwitch. For other reasons we don't set our templates to DvSwitch.
I have VMs that are templates so when I run the following weekly script I'd like to tag or append the displayed output with "-template" or perhaps even not display the templates.
Any thoughts?
Just to make sure, you want to also list the templates that are connected to a portgroup on a dvSwitch ?
If yes, will you provide the name of the portgroup ?
Or should the script do a generic search for dvSwitch portgroups ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If I am reading your request correctly...it should be as easy as setting up a switch parameter then finding all the templates...you may want to look at the template format to be something you are looking for...hope this helps
param([switch]$template)
if($template)
$vmtemplates=get-template
LucD:
Thanks for presenting at VMworld.
I am only concerned with generic dvSwitch portgroups.
Thanks,
Rob
Thanks, much appreciated.
To get all the templates that are attached to portgroups on dvSwitches, you use something like this
Get-VirtualSwitch -Distributed | Get-VirtualPortGroup | %{ if($_.ExtensionData.Vm){ Get-View -Id $_.ExtensionData.Vm |
where {$_.Config.Template} |
Select Name
} }
It gets each dvSwitch portgroup and looks at the connected VirtualMachines. On those it only selects the ones that are Templates.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference