ClusterMinimumValues.psm1
# 06/09/2016 sfish Created. # 05/25/2017 sfish Handled condition where cluster service is not running. # 09/12/2018 sfish Moved to class from MOF. enum Ensure { True False } [DscResource()] class ClusterMinimumValues { [DscProperty(Key)] [System.Int32]$CrossSubnetDelay [DscProperty(Key)] [System.Int32]$CrossSubnetThreshold [DscProperty(Key)] [System.Int32]$SameSubnetDelay [DscProperty(Key)] [System.Int32]$SameSubnetThreshold [DscProperty(Key)] [Ensure]$Ensure [void] Set() { if (Get-Module -ListAvailable -Name FailoverClusters) { try { $paf = Get-Cluster -ErrorAction Stop #CrossSubnetDelay if (($paf).CrossSubnetDelay -eq 1000) { ($paf).CrossSubnetDelay = this.$CrossSubnetDelay } #CrossSubnetThreshold if (($paf).CrossSubnetThreshold -eq 5) { ($paf).CrossSubnetThreshold = this.$CrossSubnetThreshold } #SameSubnetDelay if (($paf).SameSubnetDelay -eq 1000) { ($paf).SameSubnetDelay = this.$SameSubnetDelay } #SameSubnetThreshold if (($paf).SameSubnetThreshold -eq 5) { ($paf).SameSubnetThreshold = this.$SameSubnetThreshold } } catch { if($_.Exception.Message -like '*The cluster service is not running*') { Write-Verbose 'Cluster service is not running, exiting.' } else { Write-Verbose $_.Exception.Message } } } else { Write-Verbose "Not a failover cluster." } } [bool] Test() { $result = [System.Boolean] $result = $false; if (Get-Module -ListAvailable -Name FailoverClusters) { try { $paf = Get-Cluster -ErrorAction Stop #CrossSubnetDelay if (($paf).CrossSubnetDelay -eq 1000) { $result = $false; } else { #CrossSubnetThreshold if (($paf).CrossSubnetThreshold -eq 5) { $result = $false; } else { #SameSubnetDelay if (($paf).SameSubnetDelay -eq 1000) { $result= $false; } else { #SameSubnetThreshold if (($paf).SameSubnetThreshold -eq 5) { $result=$false; } else { $result=$true; } } } } } catch { if($_.Exception.Message -like '*The cluster service is not running*') { Write-Verbose "The cluster service is not running, now exiting." $result = $true } else { Write-Verbose $_.Exception.Message $result = $false } } } else { Write-Verbose "Not a failover cluster" $result = $true } return $result } [ClusterMinimumValues] Get() { $tmpCrossSubnetDelay = 0 $tmpCrossSubnetThreshold = 0 $tmpSameSubnetDelay = 0 $tmpSameSubnetThreshold = 0 if (Get-Module -ListAvailable -Name FailoverClusters) { try { $paf = Get-Cluster -ErrorAction Stop $tmpCrossSubnetDelay = ($paf).CrossSubnetDelay $tmpCrossSubnetThreshold = ($paf).CrossSubnetThreshold $tmpSameSubnetDelay = ($paf).SameSubnetDelay $tmpSameSubnetThreshold = ($paf).SameSubnetThreshold } catch { if($_.Exception.Message -like '*The cluster service is not running*') { Write-Verbose "The cluster service is not running, now exiting." } else { Write-Verbose $_.Exception.Message } } } else { Write-Verbose "Not a failover cluster" } $returnValue = @{ CrossSubnetDelay = $tmpCrossSubnetDelay CrossSubnetThreshold = $tmpCrossSubnetThreshold SameSubnetDelay = $tmpSameSubnetDelay SameSubnetThreshold = $tmpSameSubnetThreshold Ensure = "Present" } return $returnValue; } } |