Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Script to loop through SQL Server Instances and pass Instance Name to Connection String

$
0
0
I am trying to use a SQL Table to loop through SQL Instances and pass the Instance to a script:$DestinationSQLServer = 'coaidera01\idera'$DestinationDBName = 'CTM_Monitoring'$DestinationQry = "select InstanceName from COA_SQLServerInstanceInfo WHERE InstanceName Like 'coaidera01\idera'"$SQLSvr = get-SqlData -sqlserver $DestinationSQLServer -dbname $DestinationDBName -qry $DestinationQry$SQLSvr | foreach { $myserver = $_$MySQL = new-object Microsoft.SqlServer.Management.Smo.Server $myserver;------------------------------------------------------------------------------I get this error: The following exception was thrown when trying to enumerate the collection: "Failed to connect to server System.Data.DataRow.".Any Clues

Viewing all articles
Browse latest Browse all 467

Trending Articles