[英]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?? 我需要作为批处理文件或Windows计划任务来运行sql server powershell脚本(使用invoke-sqlcmd)的哪些管理单元或初始化程序?
I have tried the following: 我尝试了以下方法:
# mysqlscript.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 ). 其中,init-sql.ps1是Microsoft所描述的提供程序初始化(请参阅将SQL Server管理单元添加到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. 发生的只是打开powershell命令提示符。 I'm pretty sure that the invoke-sqlcmd is not executed. 我很确定不会执行invoke-sqlcmd。
Thanks Emi 谢谢Emi
If all you want to do is use invoke-sqlcmd you could use a very simple function in its place: 如果您只想使用invoke-sqlcmd,则可以使用一个非常简单的函数代替它:
Copy the function invoke-sqlcmd2 into your script: 将函数invoke-sqlcmd2复制到脚本中:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.