DSCClassResources/DistributedCluster/DistributedCluster.psm1

[DscResource()]
class DistributedCluster {
    [DscProperty(Key)]
    [string] $ClusterName

    [DscProperty(Mandatory)]
    [string]$ClusterDomain

    [DscProperty(Mandatory=$false)]
    [ValidateSet("Distributed")]
    [string]$ManagementNetworkMode = "Distributed"

    [DscProperty(Mandatory=$false)]
    [ValidateSet("ActiveDirectoryAndDns")]
    [string]$AdministrativeAccessPoint = "ActiveDirectoryAndDns"

    [DscProperty(Mandatory=$false)]
    [String]$NodeName = $env:COMPUTERNAME

    [DscProperty(Mandatory=$false)]
    [string[]]$ClusterNodeArr = @()

    
    # Gets the resource's current state.
    [DistributedCluster] Get() {
        $clusterObj = Get-Cluster
        $this.ClusterDomain = $clusterObj.Domain
        $this.ClusterName = $clusterObj.Name
        $this.AdministrativeAccessPoint = $clusterObj.AdministrativeAccessPoint
        return $this
    }
    
    # Sets the desired state of the resource.
    [void] Set() {
        foreach ($node in $this.ClusterNodeArr) {
            Write-Verbose "Checking Cluster Node: $node"
            try {
                $clusterObj = Get-Cluster -Name $node -erroraction Stop
            }
            catch [System.Management.Automation.ActionPreferenceStopException] {
                $clusterObj = $null
            }
            if ($clusterObj) {
                Write-Verbose "Cluster already exists..."
                $clusterObj | Add-ClusterNode -Name $this.NodeName -NoStorage
                return
            }
        }
        $clusterParam = @{
            Name = $this.ClusterName
            Node = ([System.Net.Dns]::GetHostByName($this.NodeName)).Hostname
            NoStorage = $true
            #ManagementPointNetworkType = $this.ManagementNetworkMode
            AdministrativeAccessPoint = $this.AdministrativeAccessPoint
        }
        if ((Get-Command).Parameters.Keys -contains "ManagementNetworkMode") {
            Write-Verbose "Adding parameter for Management Network Type"
            $clusterParam.Add("ManagementNetworkMode",$this.ManagementNetworkMode)
        }
        else {
            Write-Verbose "Management Network Type Parameter not supported"
        }
        Write-Verbose "Creating Cluster: $($this.ClusterName)"
        New-Cluster @clusterParam
    }
    
    # Tests if the resource is in the desired state.
    [bool] Test() {
        $isClusterNode = Test-Path -Path 'HKLM:\Cluster'
        return $isClusterNode
    }
}