﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / Powershell  / Script to loop through SQL Server Instances and pass Instance Name to Connection String / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 14:54:30 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Script to loop through SQL Server Instances and pass Instance Name to Connection String</title><link>http://www.sqlservercentral.com/Forums/Topic1382156-1351-1.aspx</link><description>If you get-member in get-sqldata you will see that it returns a System.Data.DataRow and the properties related to your query. This is what you need to use :In you query,the name of the Instance is InstanceName  rigth ?Change you script to :$myserver = $_.InstanceName and will work :)</description><pubDate>Sun, 18 Nov 2012 13:01:02 GMT</pubDate><dc:creator>Laerte Poltronieri Junior-367636</dc:creator></item><item><title>Script to loop through SQL Server Instances and pass Instance Name to Connection String</title><link>http://www.sqlservercentral.com/Forums/Topic1382156-1351-1.aspx</link><description>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</description><pubDate>Wed, 07 Nov 2012 13:27:13 GMT</pubDate><dc:creator>george.auckland 44813</dc:creator></item></channel></rss>