There was a requirement to add a SQL Server login to a group of SQL Servers.
The SQL Server login was to be uniform across all the servers. I tend to use SQLCMD for most
DBA tasks - and as my account is Windows based and with high level of privileges , I didn't
have to worry about supplying a different username / password for every SQL Serve instance.
This powershell script is very simple , iterating through a list of SQL Server instances which are
stored in a text file . For every instance a SQLCMD is run . This is done through the "invoke-expression" call.
This allows the DBA to maintain their sql scripts separately , which can be executed against any number of instances
-----------------CODE STARTS---------------------------
foreach ($svr in get-content "C:\MyInstances.txt"){
$svr
invoke-expression "SQLCMD -E -S $svr -i createMyuser.sql"
}
-------------CODE FINISHES----------------
How would you execute SQLCMD \Lc so that its results would be used instead of the text list? I tried various versions of get-process, get-command, and get-content with no success.
Thanks
Posted by: mbourgon | April 22, 2009 at 10:58 AM
Nevermind:
foreach ($svr in (sqlcmd /Lc))
{
invoke-expression "SQLCMD -E -S $svr -i c:\test.sql"
}
Posted by: mbourgon | April 22, 2009 at 01:51 PM
I find the method SQLCMD \Lc not reliable , and in often fails.I've seen it fail for a bunch of different reasons. Which is why I rely on the prepared list
Posted by: Jack Vamvas | May 02, 2009 at 01:07 AM