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
#
# Must be run with a Global service account.
@@ -12,16 +12,20 @@
# Set-RscServiceAccountFile sa.json -OutputFilePath sa-rbksql.xml
#
# Example invocation
# .\claimInstance.ps1 -sqlInstance "sqlfcsql\TESTINST" -mvName "JP-ZF-SQL"
# .\setActiveNode.ps1 -SqlInstance "sqlfcsql\TESTINST" -mvName "JP-ZF-SQL"
#
# v0.1 Initial Release
#
##########################################################################
param (
[Parameter(Mandatory=$False,
[Parameter(Mandatory=$True,
HelpMessage="Instance to claim")]
[string]$sqlInstance,
[string]$SqlInstance,
[Parameter(Mandatory=$True,
HelpMessage="Managed Volume name")]
[string]$mvName,
[Parameter(Mandatory=$False,
HelpMessage="Do not change the MV")]
@@ -29,10 +33,8 @@ param (
)
# SA File must be an absolute path
$SAFile = "C:\Rubrik\scripts\sa-rbksql.xml"
$logFile = "C:\Rubrik\scripts\claimInstance.log"
$mvName = "JP-ZF-SQL"
$sqlInstance = "sqlfcsql\TESTINST"
$SAFile = "C:\Rubrik\scripts\sa.xml"
$logFile = "C:\Rubrik\scripts\setActiveNode.log"
$checkCluster = $true
###########################
@@ -53,13 +55,13 @@ Import-Module RubrikSecurityCloud
if ($checkCluster) {
# Check if SQL instance is running locally
$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)" }
if ($clusterInstance) {
$ownerNode = $clusterInstance.OwnerNode
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
Write-Log "Connected to Rubrik Security Cloud."
@@ -108,10 +110,10 @@ if ($checkCluster) {
exit 1
} 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 {
Write-Log "ERROR: SQL instance '$sqlInstance' not found in cluster resources."
Write-Log "ERROR: SQL instance '$SqlInstance' not found in cluster resources."
exit 1
}
} else {