Created
August 26, 2017 23:46
Revisions
-
Packet-Lost created this gist
Aug 26, 2017 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ ##replace variables as needed## $Server = 'AvailabilityGroupListener.fqdn.com' $Database = 'DatabaseInsideAvailabilityGroup' $Connection = New-Object System.Data.SQLClient.SQLConnection $Connection.ConnectionString = "Server=$($Server);Database=$($Database);Integrated Security=True;MultiSubnetFailover=True" $Connection.Open() $Command = New-Object System.Data.SQLClient.SQLCommand $Command.Connection = $Connection $Command.CommandText = 'Select @@SERVERNAME' $Reader = $Command.ExecuteReader() $Datatable = New-Object System.Data.DataTable $Datatable.Load($Reader) $Datatable $Connection.Close() $Connection = New-Object System.Data.SQLClient.SQLConnection $Connection.ConnectionString = "Server=$($Server);Database=$($database);Integrated Security=True;MultiSubnetFailover=True;ApplicationIntent=ReadOnly" $Connection.Open() $Command = New-Object System.Data.SQLClient.SQLCommand $Command.Connection = $Connection $Command.CommandText = 'Select @@SERVERNAME' $Reader = $Command.ExecuteReader() $Datatable = New-Object System.Data.DataTable $Datatable.Load($Reader) $Datatable $Connection.Close()