Parameterise setActiveNode

This commit is contained in:
2025-10-22 10:10:09 +01:00
parent 14966f87a1
commit 907449914a

View File

@@ -1,6 +1,6 @@
########################################################################## ##########################################################################
# #
# Update an SLA MV to point to the local host # Update an SLA MV to point to the correct host
# Created by Rubrik PS for ZF, September 2025 # Created by Rubrik PS for ZF, September 2025
# #
# Must be run with a Global service account. # Must be run with a Global service account.
@@ -12,16 +12,20 @@
# Set-RscServiceAccountFile sa.json -OutputFilePath sa-rbksql.xml # Set-RscServiceAccountFile sa.json -OutputFilePath sa-rbksql.xml
# #
# Example invocation # Example invocation
# .\claimInstance.ps1 -sqlInstance "sqlfcsql\TESTINST" -mvName "JP-ZF-SQL" # .\setActiveNode.ps1 -SqlInstance "sqlfcsql\TESTINST" -mvName "JP-ZF-SQL"
# #
# v0.1 Initial Release # v0.1 Initial Release
# #
########################################################################## ##########################################################################
param ( param (
[Parameter(Mandatory=$False, [Parameter(Mandatory=$True,
HelpMessage="Instance to claim")] HelpMessage="Instance to claim")]
[string]$sqlInstance, [string]$SqlInstance,
[Parameter(Mandatory=$True,
HelpMessage="Managed Volume name")]
[string]$mvName,
[Parameter(Mandatory=$False, [Parameter(Mandatory=$False,
HelpMessage="Do not change the MV")] HelpMessage="Do not change the MV")]
@@ -29,10 +33,8 @@ param (
) )
# SA File must be an absolute path # SA File must be an absolute path
$SAFile = "C:\Rubrik\scripts\sa-rbksql.xml" $SAFile = "C:\Rubrik\scripts\sa.xml"
$logFile = "C:\Rubrik\scripts\claimInstance.log" $logFile = "C:\Rubrik\scripts\setActiveNode.log"
$mvName = "JP-ZF-SQL"
$sqlInstance = "sqlfcsql\TESTINST"
$checkCluster = $true $checkCluster = $true
########################### ###########################
@@ -53,13 +55,13 @@ Import-Module RubrikSecurityCloud
if ($checkCluster) { if ($checkCluster) {
# Check if SQL instance is running locally # Check if SQL instance is running locally
$localNode = $env:COMPUTERNAME $localNode = $env:COMPUTERNAME
$instanceName = $sqlInstance.Split('\')[1] $instanceName = $SqlInstance.Split('\')[1]
$clusterInstance = Get-ClusterResource | Where-Object { $_.ResourceType -eq "SQL Server" -and $_.Name -eq "SQL Server ($instanceName)" } $clusterInstance = Get-ClusterResource | Where-Object { $_.ResourceType -eq "SQL Server" -and $_.Name -eq "SQL Server ($instanceName)" }
if ($clusterInstance) { if ($clusterInstance) {
$ownerNode = $clusterInstance.OwnerNode $ownerNode = $clusterInstance.OwnerNode
if ($ownerNode -ne $localNode) { if ($ownerNode -ne $localNode) {
Write-Log "SQL instance '$sqlInstance' is not running on local node '$localNode'. Updating the MV." Write-Log "SQL instance '$SqlInstance' is not running on local node '$localNode'. Updating the MV."
Connect-Rsc -ServiceAccountFile $SAFile Connect-Rsc -ServiceAccountFile $SAFile
Write-Log "Connected to Rubrik Security Cloud." Write-Log "Connected to Rubrik Security Cloud."
@@ -108,10 +110,10 @@ if ($checkCluster) {
exit 1 exit 1
} else { } else {
Write-Log "SQL instance '$sqlInstance' is running on local node '$localNode'. No action needed." Write-Log "SQL instance '$SqlInstance' is running on local node '$localNode'. No action needed."
} }
} else { } else {
Write-Log "ERROR: SQL instance '$sqlInstance' not found in cluster resources." Write-Log "ERROR: SQL instance '$SqlInstance' not found in cluster resources."
exit 1 exit 1
} }
} else { } else {