Set-Cluster-Alarms.psm1

function Set-Cluster-Alarms {
    param(
        [Parameter (Mandatory = $true,
            ValueFromPipeline = $true)]
        [String]$ClusterName,
        [parameter(Mandatory = $true,
            ParameterSetName = 'enableSet')]
        [Switch]$Enable,
        [parameter(Mandatory = $true,
            ParameterSetName = 'disableSet')]
        [Switch]$Disable
    )
    begin {
        $alarmMgr = Get-View AlarmManager
    }        

    process {
        $clusterobj = Get-Cluster $ClusterName -ErrorAction STOP
        Write-Host $clusterobj
        $esx = $clusterobj | Get-VMHost -ErrorAction STOP | Sort-Object -Property Name
        if ($Enable) {
            $esx | ForEach-Object {
                Write-Host "Enabling alarms on $_"
                $alarmMgr.EnableAlarmActions($_.Extensiondata.MoRef, $true)
            }
            Write-Host "Enabling alarms on $clusterobj"
            $alarmMgr.EnableAlarmActions($clusterobj.Extensiondata.MoRef, $true)

        }
        elseif ($Disable) {
                $esx | ForEach-Object {
                    Write-Host "Disabling alarms on $_"
                    $alarmMgr.EnableAlarmActions($_.Extensiondata.MoRef, $false)
                }    
                $alarmMgr.EnableAlarmActions($clusterobj.Extensiondata.MoRef, $false)
                Write-Host "Disabling alarms on $clusterobj"
            }
        }
    
        end {

        }
}