vCenter

 View Only
  • 1.  How can I generate particular affinity rule report from my cluster?

    Posted 9 days ago

    How can I generate particular affinity rule report from my cluster?



  • 2.  RE: How can I generate particular affinity rule report from my cluster?

    Posted 8 days ago

    could you please better clarify what are you meaning with it?



    ------------------------------
    Alessandro Tinivelli | blog.tinivelli.com | www.revobyte.it | VMCE 2024 | Veeam Legend | VCP-DCV 2023 | VVSPHT 2023 | vExpert 2024
    ------------------------------



  • 3.  RE: How can I generate particular affinity rule report from my cluster?

    Posted 8 days ago

    Try this one:

    # Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

    # Connect to the vCenter Server

    $vCenterServer = Read-Host -Prompt 'Enter Source vCenter FQDN: '

    Connect-VIServer -Server $vCenterServer

    # Specify the output CSV file path for DRS Rules

    $outputFile = "Z:\PowerCLI\AffinityRulesReport.csv"

    # Specify the output CSV file path for DRS VM Host Rules

    $outputFile2 = "Z:\PowerCLI\AffinityVMHostRulesReport.csv"

    # Get Cluster name as an input

    $clusterName = Read-Host -Prompt 'Enter Cluster Name: '

    # Retrieve all DRS rules for the cluster

    $rules = Get-Cluster -Name $clusterName | Get-DrsRule

    $rulesVMHost = Get-Cluster -Name $clusterName | Get-DrsVMHostRule

    $vms = $null

    # Create a detailed report for DRS Rules

    $report = foreach ($rule in $rules) {

        # Get associated VMs

        if ($rule.VMIds) {

            $associatedVMs = $rule.VMIds

            foreach ($associatedVM in $associatedVMs)

            {

               $vms += Get-VM -Id $associatedVM | Select-Object -ExpandProperty Name

               $vms += ","

            }

        } else {

            "No VMs"

        }

        # Output the data in an object

        [PSCustomObject]@{

            RuleName       = $rule.Name

            Enabled        = $rule.Enabled

            RuleType       = $rule.Type

            AssociatedVMs  = $vms

        }

        $vms = $null

    }

    # Create a detailed report for DRS Rules

    $reportVMHost = foreach ($ruleVMHost in $rulesVMHost) {

        # Output the data in an object

        [PSCustomObject]@{

            RuleName       = $ruleVMHost.Name

            Enabled        = $ruleVMHost.Enabled

            RuleType       = $ruleVMHost.Type

            VMGroup        = $ruleVMHost.VMGroup

            VMHostGroup    = $ruleVMHost.VMHostGroup

        }

    }

    # Export to CSV

    $report | Export-Csv -Path $outputFile -NoTypeInformation

    $reportVMHost | Export-Csv -Path $outputFile2 -NoTypeInformation