-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResume&Failback.ps1
46 lines (38 loc) · 1.5 KB
/
Resume&Failback.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Initialize variables and logging information
$clusterMaintenanceFolder = "C:\ClusterMaintenance"
$logFileName = "$clusterMaintenanceFolder\ClusterMaintenance_$(Get-Date -Format 'yyyyMMdd').log"
# Function to write to log
function Write-Log {
param (
[Parameter(Mandatory = $true)]
[string]$Message
)
Add-Content -Path $logFileName -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
# Check if the logging directory exists, create it if not
if (-not (Test-Path $clusterMaintenanceFolder)) {
New-Item -Path $clusterMaintenanceFolder -ItemType Directory | Out-Null
}
# Fetch the cluster name and node name
$clusterName = (Get-Cluster).name
$nodeName = [System.Environment]::MachineName
# Add this information to the log
Write-Log "Cluster Name: $clusterName"
Write-Log "Node Name: $nodeName"
try {
# Set the error action preference to stop
$ErrorActionPreference = 'Stop'
# Resume the node and move the roles back with immediate failback
Write-Log "Resuming node $nodeName with immediate failback..."
Resume-ClusterNode -Name $nodeName -Failback Immediate | Out-Null
Write-Log "Node $nodeName is now resumed and roles have been failed back immediately."
}
catch {
Write-Log "Error occurred while resuming node $nodeName with immediate failback: $_"
exit 1
}
finally {
# Reset the error action preference if needed
$ErrorActionPreference = 'Continue'
}
Write-Log "Cluster maintenance operations completed successfully for node $nodeName."