sql server 2008 - How do you send in multiple commands to Sql PowerShell from the Windows Command Line? -


not sure if belongs on serverfault or not...

i following instructions on this site adding registered servers sql studio management studio via powershell. works great 1 @ time, need 60 servers.

i have batch set code each create need. can't syntax right calling sqlps command line , passing in whole series of commands. batch set so:

sqlps -noexit -command { cd 'sqlserver:\sqlregistration\database engine server group\' new-item $(encode-sqlname server1) -itemtype registration -value "server=server1;integrated security=true" ... , on } 

any appreciated.

if have each individual new-item listed on separate line in ps1 file, example assuming have file named register.ps1 following lines.:

cd 'sqlserver:\sqlregistration\database engine server group\'; new-item $(encode-sqlname server1) -itemtype registration -value "server=server1;integrated security=true"  cd 'sqlserver:\sqlregistration\database engine server group\'; new-item $(encode-sqlname server2) -itemtype registration -value "server=server1;integrated security=true"  

you call sqlps this:

sqlps -noexit -command "&{c:\bin\register.ps1}" 

a better solution add parameters register.ps1

param($serverinstance)  cd 'sqlserver:\sqlregistration\database engine server group\' new-item $(encode-sqlname $server) -itemtype registration -value "server=$serverinstance;integrated security=true" 

then create file list of sql instances, example server.txt:

server1 server2 

call register.ps1 each line:

get-content c:\bin\server.txt | foreach {c:\bin\register.ps1 $_ } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -