PowerCLI

  • 1.  How to to get the Cluster Name of the Template

    Posted Jul 23, 2024 01:28 AM

    Hi,

    I am having the below script, I would like to get the clustername. but I am getting the error

    Please help!!

    $report = Get-Template | Select @{N="Folder_Name";E={(Get-View -Id $_.ExtensionData.Parent -Property Name).Name}},
        @{N="Cluster";E={(Get-VMhost -id $_.HostID).Name.Parent}},
        @{N="Host";E={(Get-VMhost -id $_.HostID).Name}},
        @{N="Template_Name";E={$_.Name}},
        @{N="vCPU";E={$_.ExtensionData.Config.Hardware.NumCPU}},
        @{N="Memory(GB)";E={$_.ExtensionData.Config.Hardware.MemoryMB/1024}},
        @{N="HDD(GB)";E={($_ | Get-HardDisk | Measure-Object -Sum CapacityGB).Sum}},
        @{N="OS";E={$_.ExtensionData.Config.GuestFullName}},
        @{N="Port Group";E={(Get-view -Id $_.ExtensionData.Network).Name}},
        @{N="Datastore"; E={(Get-Datastore -id $_.DatastoreIDlist).Name -join ","}},
        @{N='VMTX';E={$_.extensiondata.config.files.VmPathName}}
      $sum = $report | Measure-Object -sum "vCPU", "Memory(GB)", "HDD(GB)"
      $row1 = "" | Select "Folder_Name",Cluster,"Template_Name","vCPU", "Memory(GB)", "HDD(GB)"
      $report += $row1
      $row2 = "" | Select "Folder_Name",Cluster,"Template_Name","vCPU", "Memory(GB)", "HDD(GB)"
      $row2."Folder_Name" = 'Total'
      $row2."Template_Name" = (Get-Template).count
      $row2.vCPU = $sum | where{$_.Property -eq 'vCPU'} | select -ExpandProperty Sum 
      $row2."Memory(GB)" = $sum | where{$_.Property -eq "Memory(GB)"} | select -ExpandProperty Sum
      $row2."HDD(GB)" = $sum | where{$_.Property -eq "HDD(GB)"} | select -ExpandProperty Sum
      $report += $row2
      $report



  • 2.  RE: How to to get the Cluster Name of the Template

    Posted Jul 23, 2024 02:16 AM
    Edited by LucD Jul 23, 2024 02:34 AM

    Which error are you getting?

    Did you try with

    @{N="Cluster";E={(Get-VMhost -Id $_.HostID | Get-Cluster).Name}},



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


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


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