这有帮助吗?我前一阵子做了,但从来没有机会完全测试它:
#Add a new node to NLB cluster
#Tested with Windows Server 2008 R2 only
#Requires WSManCredSSP Server Role Enabled on cluster Host
Function join-NlbCluster {
Param(
[Parameter(Mandatory=$true)]
$clusterHostname,
[Parameter(Mandatory=$true)]
$newNodename,
[Parameter(Mandatory=$true)]
$newNodeinterfaceName,
[Parameter(Mandatory=$true)]
$userName,
[Parameter(Mandatory=$true)]
$password
)
Write-Verbose "Verifiying if the remote node has NLB installed"
If (!((Get-OSFeature -computerName $newNodename -featureName NLB).Installed)) {
Write-Error "NLB feature is not installed on $newNodename. Cannot continue."
return $false
}
$cmdBlock = "Import-Module networkLoadBalancingClusters
`$nlbCluster = Get-nlbCluster -HostName $clusterHostName
if (`$nlbCluster) {
`$newNode = Add-NlbClusterNode -InputObject `$nlbCluster -NewNodeName $newNodename -NewNodeInterface `"$newNodeinterfaceName`"
if (`$newNode) {
Write-Host `"New node is added to cluster`"
return `$newNode
} else {
Write-Host `"Error Creating the NLB Cluster`"
return `$false
}
} else {
Write-Host `"No NLB cluster found on $clusterHostname`"
return `$false
}"
Write-Verbose $cmdBlock
$scriptBlock = $ExecutionContext.InvokeCommand.NewScriptBlock($cmdBlock)
try {
Write-Verbose "Creating new NLB Cluster"
Invoke-Command -ComputerName $clusterHostName -ScriptBlock $scriptBlock -HideComputerName -Authentication Credssp -Credential (Get-PSCredential -userName $userName -Password $password)
}
catch {
Write-Verbose $_
return $false
}
}