powershell 测试群集检测
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 测试群集检测相关的知识,希望对你有一定的参考价值。
<#
.Synopsis
Evaluates if local device is a member of a cluster or a standalone server
.DESCRIPTION
Evaluates several factors to determine if device is a member of a cluster or acting as a standalone server. The cluster service is evaluated, and if present the cluster nodes will be tested to determine if the local device is a member. If the cluster service is not running the cluster registry location is evaluated to determine if the server's cluster membership status.
.EXAMPLE
Test-IsACluster
Returns boolean if local device is part of a cluster
.OUTPUTS
Boolean value
.NOTES
Author: Jake Morrison
http://techthoughts.info
The design of this function intends the function to be run on the device that is being evaluated
#>
function Test-IsACluster {
[CmdletBinding()]
param ()
#assume device is not a cluster
[bool]$clusterEval = $false
$nodes = $null
$clusterCheck = $null
$clusterNodeNames = $null
try {
$hostName = $env:COMPUTERNAME
Write-Verbose -Message "HostName is: $hostName"
Write-Verbose -Message "Verifying presence of cluster service..."
$clusterCheck = get-service ClusSvc -ErrorAction SilentlyContinue
if ($clusterCheck -ne $null) {
Write-Verbose -Message "Cluster Service found."
Write-Verbose -Message "Checking cluster service status..."
$clusterServiceStatus = Get-Service ClusSvc | Select-Object -ExpandProperty Status
if ($clusterServiceStatus -eq "Running") {
Write-Verbose -Message "Cluster serivce running."
Write-Verbose -Message "Evaluating cluster nodes..."
$nodes = Get-ClusterNode -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Name
if ($nodes -ne $null) {
foreach ($node in $nodes) {
if ($hostName -eq $node) {
$clusterEval = $true
Write-Verbose -Message "Hostname was found among cluster nodes."
}
}
Write-Verbose -Message "Cluster node evaulation complete."
}
}
else {
Write-Verbose -Message "Cluster service is not running. Cluster cmdlets not possible. Switching to registry evaluation..."
$clusterRegistryPath = "HKLM:\SYSTEM\CurrentControlSet\Services\ClusSvc\Parameters"
$clusterNodeNames = Get-ItemProperty -Path $clusterRegistryPath -ErrorAction SilentlyContinue | Select-Object -ExpandProperty NodeNames -ErrorAction Stop
if ($clusterNodeNames -ne $null) {
if ($clusterNodeNames -like "*$hostName*") {
$clusterEval = $true
Write-Verbose -Message "Hostname was found in cluster registy settings"
}
else {
Write-Verbose -Message "Hostname was not found in cluster registry settings."
}
}
}
}
else {
Write-Verbose -Message "No cluster service was found."
}
}
catch {
Write-Verbose -Message "There was an error determining if this server is part of a cluster."
Write-Error $_
}
return $clusterEval
}
以上是关于powershell 测试群集检测的主要内容,如果未能解决你的问题,请参考以下文章
使用Powershell配置Windows Failover Cluster群集
无法通过 Powershell 或 Visual Studio 连接到受保护的 Azure Service Fabric 群集