DSCClassResources/ClusterParameter/ClusterParameter.psm1

[DscResource()]
class ClusterParameter {
    [DscProperty(Mandatory)]
    [string] $ClusterName

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

    [DscProperty(Key)]
    [String]$Key

    [DscProperty(Mandatory)]
    [String]$Value

    [DscProperty(Mandatory=$false)]
    [String]$ClusterResourceName = 'Cluster Name'

    
    # Gets the resource's current state.
    [ClusterParameter] Get() {
        $clusterResource = Get-ClusterResource -Name $this.ClusterResourceName
        $this.Value = ($clusterResource | Get-ClusterParameter -Name $this.key).Value
        $this.Type = ($clusterResource | Get-ClusterParameter -Name $this.key).Type
        return $this
    }
    
    # Sets the desired state of the resource.
    [void] Set() {
        Get-ClusterResource -Name $this.ClusterResourceName | Set-ClusterParameter -Name $this.Key -Value $this.Value
        Write-Verbose -Message 'Restarting network name ressource (synchronously)'
        Stop-ClusterResource -Name $this.ClusterResourceName
        Start-ClusterResource -Name $this.ClusterResourceName
    }
    
    # Tests if the resource is in the desired state.
    [bool] Test() {
        $clusterResource = Get-ClusterResource -Name $this.ClusterResourceName
        $currentValue = ($clusterResource | Get-ClusterParameter -Name $this.key).Value
        if ($currentValue -eq $this.Value) {
            return $true
        } 
        else {
            return $false
        }
    }
}