Which snapins do I need to run sql server powershell?
what snapins or initializations do I need to run a sql server powershell script (using invoke-sqlcmd), as a batch file or windows scheduled task??
I have tried the following:
# mys开发者_StackOverflow中文版qlscript.ps1
. "D:\Posh\init-sql.ps1"
invoke-sqlcmd .....
where init-sql.ps1 is the provider initialization as described by Microsoft (see Adding the SQL Server Snap-ins to Windows PowerShell).
Then, I tried the following:
powershell.exe -noe "D:\Posh\mysqlscript.ps1"
What happens is just the opening of the powershell command prompt. I'm pretty sure that the invoke-sqlcmd is not executed.
Thanks Emi
If all you want to do is use invoke-sqlcmd you could use a very simple function in its place:
Copy the function invoke-sqlcmd2 into your script:
http://poshcode.org/2279
精彩评论