Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Script to loop through SQL Server Instances and pass Instance Name to Connection String Expand / Collapse
Author
Message
Posted Wednesday, November 7, 2012 1:27 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, September 12, 2014 11:37 AM
Points: 5, Visits: 83
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
Post #1382156
Posted Sunday, November 18, 2012 1:01 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 11, 2014 10:06 PM
Points: 158, Visits: 776
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 :)


$hell your Experience !!!
Post #1386090
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse