PowerCLI

  • 1.  Template details: PowerCLI

    Broadcom Employee
    Posted Apr 05, 2012 09:37 AM

    Hi All,

    I need a script on the templates details please, below is something I am looking for. There are about 70 templates, it is difficult to convert them one by one and check the details.

    1. Template Name

    2. Number of disks and their sizes

    3. vCPU

    4. RAM Size

    Thank you,

    Nick



  • 2.  RE: Template details: PowerCLI

    Posted Apr 05, 2012 09:51 AM

    No need to convert.

    This is a quick and dirty method to get at the info

    Get-Template | Select Name,
        @{N="HD#";E={@($_.ExtensionData.Config.Hardware.Device | 
            where{$_.GetType().Name -eq "VirtualDisk"}).Count}},
        @{N="HD Size (KB)";E={[string]::Join(',',( $_.ExtensionData.Config.Hardware.Device | 
            where{$_.GetType().Name -eq "VirtualDisk"} |
            %{$_.CapacityInKB}))}},
        @{N="vCPU";E={$_.ExtensionData.Config.Hardware.NumCPU}},
        @{N="RAM (MB)";E={$_.ExtensionData.Config.Hardware.MemoryMB}}
    


  • 3.  RE: Template details: PowerCLI

    Posted Jan 31, 2025 01:43 PM

    Hi LucD,

    Can you please help me to get the details of the template assigned to the desktop pool.
    I want to check the assigned template of the desktop pools.

    Thank you




  • 4.  RE: Template details: PowerCLI

    Posted Jan 31, 2025 01:44 PM

    Horizon View changed owner, please raise your question in the Omnissa forums.



    ------------------------------


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


    ------------------------------



  • 5.  RE: Template details: PowerCLI

    Posted Apr 05, 2012 09:52 AM

    Hi Nick,

    the next PowerCLI script will give you the desired information about your templates:

    Get-Template |
    ForEach-Object {
      if ($_)
      {
        $Template = $_
        "" | Select-Object -Property @{N="Template Name";E={$Template.Name}},
          @{N="NumDisks";E={($Template | Get-HardDisk | Measure-Object).Count}},
          @{N="DiskSizesGB";E={[string]::Join(' ',($Template | Get-HardDisk | ForEach-Object {[Math]::Round($_.CapacityKB/1MB,0)}))}},
          @{N="NumCPU";E={$Template.ExtensionData.Config.Hardware.NumCPU}},
          @{N="MemoryMB";E={$Template.ExtensionData.Config.Hardware.MemoryMB}}
      }
    }
    
    

    Regards, Robert



  • 6.  RE: Template details: PowerCLI

    Broadcom Employee
    Posted Apr 05, 2012 10:03 AM

    thanks very much Robert/Luc,

    Both the scripts worked perfect! :smileyhappy:

    Forgot to add the date, please can you add the Date when the template was created too?

    Is there any way the output can be saved in excel sheet coloumn wise. Else it will again be a manual job to organise the output.

    Cheers!



  • 7.  RE: Template details: PowerCLI
    Best Answer

    Posted Apr 05, 2012 10:13 AM

    The creation date is not in the template object. There are ways to find it in the eventlog. Alan Renouf made a blogpost Who created that VM? It show a way to find the creation date.

    To write the output to a .csv file you can append the following to the last line of the script:

    | Export-CSV -Path Templates.csv -UseCulture -NoTypeInformation


  • 8.  RE: Template details: PowerCLI

    Posted Apr 05, 2012 11:07 AM

    This will give the first date when the VM was marked as a Template.

    If you don't keep all the events, older templates might be missing a date.

    Get-Template | Select Name,
        @{N="HD#";E={@($_.ExtensionData.Config.Hardware.Device | 
            where{$_.GetType().Name -eq "VirtualDisk"}).Count}},
        @{N="HD Size (KB)";E={[string]::Join(',',( $_.ExtensionData.Config.Hardware.Device | 
            where{$_.GetType().Name -eq "VirtualDisk"} |
            %{$_.CapacityInKB}))}},
        @{N="vCPU";E={$_.ExtensionData.Config.Hardware.NumCPU}},
        @{N="RAM (MB)";E={$_.ExtensionData.Config.Hardware.MemoryMB}},
        @{N="Created";E={(Get-VIEvent -Entity $_ -maxsamples ([int]::MaxValue) | 
                where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.markAsTemplate"} |
                Sort-Object -Property CreatedTime | Select -First 1).CreatedTime}} |
    Export-Csv .\template-report.csv -NoTypeInformation -UseCulture 

    If you want to see the date the VM was created as the date, that requires re-writing the Where-clause