Automation

 View Only
  • 1.  Cluster Config & Resources

    Posted Dec 16, 2019 02:44 PM

    Im trying to pull a list of cluster resources but im having a couple of issues with the sections highlighted red

    Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice |

    Select Name, HAEnabled, DRSEnabled,

    @{N=“TotalCores“;E={Get-VMHost -Location $_ | Measure-Object NumCpu -Sum | Select -ExpandProperty Sum}},

    @{N=“ProvisionedCores“;E={Get-VMHost -Location $_ | get-vm | Measure-Object NumCpu -Sum | Select -ExpandProperty Sum}},

    @{N=“CoresRatio“;E={[INT]($_.ProvisionedCores/$_.TotalCores)}},

    @{N=“TotalMem“;E={[math]::Round(Get-VMHost -Location $_ | Measure-Object MemoryTotalGB -Sum | Select -ExpandProperty Sum)}},

    @{N=“ProvisionedMem“;E={Get-VMHost -Location $_ | get-vm | Measure-Object MemoryGB -Sum | Select -ExpandProperty Sum}} | FT

    "CoresRatio" just returns no value

    "TotalMem" works if i take the math out trying to round the number but it displays too many decimal places

    Any idea what i am doing wrong? Thanks!



  • 2.  RE: Cluster Config & Resources
    Best Answer

    Posted Dec 16, 2019 02:52 PM

    You can't refer to the select output you are building like that.

    Remember, the $_ symbol represents a Cluster object coming from the Get-Cluster cmdlet.

    You can use a variable in the script scope.

    Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice |

    Select Name, HAEnabled, DRSEnabled,

    @{N=“TotalCores“;E={

        $script:totalCores = Get-VMHost -Location $_ | Measure-Object NumCpu -Sum | Select -ExpandProperty Sum

        $script:totalCores}},

    @{N=“ProvisionedCores“;E={

        $script:provisionedcores = Get-VMHost -Location $_ | get-vm | Measure-Object NumCpu -Sum | Select -ExpandProperty Sum

        $script:provisionedcores}},

    @{N=“CoresRatio“;E={[int]($script:provisionedcores/$script:totalcores)}},

    @{N=“TotalMem“;E={[math]::Round((Get-VMHost -Location $_ | Measure-Object MemoryTotalGB -Sum | Select -ExpandProperty Sum))}},

    @{N=“ProvisionedMem“;E={Get-VMHost -Location $_ | get-vm | Measure-Object MemoryGB -Sum | Select -ExpandProperty Sum}} | FT



  • 3.  RE: Cluster Config & Resources

    Posted Dec 16, 2019 02:57 PM

    Ah you learn something new every day, makes sense about $_ ! However I didn't realize you can define a variable and call it within an expression. Works perfectly, thanks!