It is possible to retrieve template information using the Get-Template cmdlet to obtain a number of properties. In this example I will be looking to retrieve the following items and export to comma-separated values (CSV) file:
- Name
- vCPU
- Memory
- Number of Hard Disks
- Size of Hard Disks
Firstly, we will connect to the VI Server and return a collection of templates using the Get-Template cmdlet.
If (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { Add-PSSnapin VMware.VimAutomation.Core > $null } Connect-VIServer server1.domain.local $Templates = Get-Template
For each template in the collection we will retrieve the above items and store these in a variable for exporting to a CSV file. For the number of hard disks, these will count the number retrieved and for size join the values to a single string by invoking the Get-HardDisk cmdlet.
$Inventory= ForEach ($Template in$Templates) { "" | Select-Object -Property @{N="Name";E={$Template.Name}}, @{N="vCPU";E={$Template.ExtensionData.Config.Hardware.NumCPU}}, @{N="Memory (MB)";E={$Template.ExtensionData.Config.Hardware.MemoryMB}}, @{N="Number of Hard Disks";E={($Template | Get-HardDisk | Measure-Object).Count}}, @{N="Size of Hard Disks";E={[string]::Join(',',(($Template |Get-HardDisk).CapacityKB))}} } $Inventory | Export-Csv -NoTypeInformation -UseCulture -Path ("D:\Output\" + [guid]::NewGuid() + "-inv_template.csv")