July 7, 2023 at 5:26 pm
Team,
Why does the below not work? Using parameters for listener name and ip addresses. When i hard code the IP addresses in there it works even with the listener as a parameter . I assume it has to do with the quotes. Any assistance is greatly appreciated. See full section of code not including the parameter request to enter.
I have tried
$AddListener = @"
USE [master]
GO
ALTER AVAILABILITY GROUP [$AGName]
ADD LISTENER N'$LsnrName' (
WITH IP
((N'$IP1', N'255.255.252.0'),
(N'$IP2', N'255.255.252.0'),
(N'$IP3', N'255.255.252.0')
)
, PORT=$SrvPort);
"@
invoke-sqlcmd -query $AddListener -Database "master" -ServerInstance $SQLInstance -ErrorAction SilentlyContinue
¤ §unshine ¤
July 7, 2023 at 6:35 pm
Not sure why it isn't working, but you don't need to splat it, that is a single string variable for -query. Just use [string]$addListner = "..." to start with.
Does the SQL command work running it as SQL in dev?
July 7, 2023 at 8:14 pm
RESOLUTION: Yes regular sql or even as powershell hardcoded without parameters it works. However, just found resolution. Use pure powershell. While i couldnt find an exact example, i just tried it myself and it worked!
New-SqlAvailabilityGroupListener -Name $LsnrName -StaticIp "$IP1/255.255.252.0","$IP2/255.255.252.0","$IP1/255.255.252.0" -Path "SQLSERVER:\SQL\PrimaryServer\MSSQLSERVER\AvailabilityGroups\AGName" -Port $Port
¤ §unshine ¤
July 11, 2023 at 9:53 am
This was removed by the editor as SPAM
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply