ps/Modules/Alkami.PowerShell.ServiceFabric/Public/Disable-AlkamiServiceFabricNode.ps1
2023-05-30 22:51:22 -07:00

67 lines
2.3 KiB
PowerShell

function Disable-AlkamiServiceFabricNode {
<#
.SYNOPSIS
State transitions a Service Fabric node to 'Disabled' and monitors that state transition to
completion (by default).
.PARAMETER Hostname
[string] The host name of the server in the Service Fabric cluster to disable. If not provided, defaults to localhost.
.PARAMETER Intent
[string] The reason the Service Fabric node is being disabled. Defaults to 'Restart'.
Refer to https://docs.microsoft.com/en-us/powershell/module/servicefabric/disable-servicefabricnode?view=azureservicefabricps
.PARAMETER TimeoutMinutes
[byte] The length of time in minutes to monitor the node for state transition completion before declaring that an error
has occurred. Defaults to 10 minutes.
.PARAMETER SleepIntervalSeconds
[byte] The length of time in seconds to pause between node status queries. Defaults to 15 seconds.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$Hostname = 'localhost',
[Parameter(Mandatory = $false)]
[ValidateSet('Invalid', 'Pause', 'Restart', 'RemoveData', 'RemoveNode', IgnoreCase = $false)]
[string]$Intent = 'Restart',
[Parameter(Mandatory=$false)]
[byte]$TimeoutMinutes = 10,
[Parameter(Mandatory=$false)]
[ValidateRange(1, 120)]
[byte]$SleepIntervalSeconds = 15
)
$loglead = (Get-LogLeadName)
Connect-AlkamiServiceFabricCluster -Hostname $Hostname
if ( $Hostname -eq 'localhost' ) {
$actualHostname = "$env:COMPUTERNAME"
} else {
$actualHostname = $Hostname
}
# Node names are case sensitive. Resolve our hostname into a cluster node name ignoring case.
$curNode = ( Get-ServiceFabricNode | Where-Object { $_.NodeName -eq $actualHostname } | Select-Object -First 1 )
if ( ! $curNode ) {
Write-Error "$loglead : Could not retrieve the Service Fabric node for $actualHostname."
return
} else {
$nodeName = $curNode.NodeName
}
Disable-ServiceFabricNode -NodeName $nodeName -Intent $Intent -Force
Wait-AlkamiServiceFabricNodeStatus -DesiredStatus 'Disabled' -Hostname $nodeName -TimeoutMinutes $TimeoutMinutes -SleepIntervalSeconds $SleepIntervalSeconds -SkipHealthCheck
}