如何从 Windows 命令行向 Sql PowerShell 发送多个命令? [英] How do you send in multiple commands to Sql PowerShell from the Windows Command Line?

查看:44
本文介绍了如何从 Windows 命令行向 Sql PowerShell 发送多个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这是否属于服务器故障...

Not sure if this belongs on serverfault or not...

我正在按照 this 站点,用于通过 powershell 将注册服务器添加到 sql studio management studio.一次运行一个很好,但我需要为 60 个服务器这样做.

I am following the instructions on this site for adding registered servers to sql studio management studio via powershell. It works great one at a time, but I need to do it for 60 servers.

我有一个批处理设置,其中包含我需要的每个创建的代码.我无法获得通过命令行调用 sqlps 并传入整个系列命令的正确语法.我的批次设置如下:

I have a batch set up with the code for each create that I need. I can't get the syntax right for calling sqlps by the command line and passing in the whole series of commands. My batch is set up like so:

sqlps -NoExit -Command { cd 'SQLSERVER:\sqlregistration\Database Engine Server Group\' new-item $(Encode-Sqlname server1) -itemtype registration -Value "server=server1;integrated security=true" ... and so on }

感谢任何帮助.

推荐答案

感谢@Chad 为我指明了正确的方向,我想出了这个,并且奏效了:

Thanks to @Chad pointing me in the right direction, I came up with this, which worked:

一个多行的批处理文件,每一行看起来像这样:

A batch file with multiple lines, each line looking like this:

sqlps -Command "&{ cd 'SQLSERVER:\sqlregistration\Database Engine Server Group'; new-item $(Encode-Sqlname serverX) -itemtype registration -Value \"server=serverX;integrated security=true\";}" 

这篇关于如何从 Windows 命令行向 Sql PowerShell 发送多个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆