troubleshooting Question

Executing a SQL stored procedure using PowerShell

Avatar of JenH2
JenH2Flag for United States of America asked on
Powershell
14 Comments1 Solution4939 ViewsLast Modified:
I know how to do all this in VBScript, but I'm forcing myself to do everything in PowerShell now, cause I'll never learn it if I don't use it...

I'm simply trying to parse a list of servers (I have a DSN for each) and execute a stored procedure on them.  Can someone point out what I've got wrong?

I keep getting "Exception setting "ConnectionString": "Keyword not supported: 'dsn'."" error on line 7.

$Servers = Get-Content C:\Scripts\servers.txt

ForEach($Server in $Servers)
{
$connstr = "DSN=$Server;"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
$SQLConnection.ConnectionString = $connstr
$SqlCommandText = "exec stored_procedure"
$SQLConnection.Open()
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand($SqlCommandText, $SQLConnection)
$SqlCmd.ExecuteReader()
}
ASKER CERTIFIED SOLUTION
Chris Dent
PowerShell Developer
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros