November 7, 2012 at 1:27 pm
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
November 18, 2012 at 1:01 pm
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
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy