如何在PowerShell中运行以下命令?
C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe -verb:sync -source:dbfullsql="数据源=mysource;集成安全=false;用户ID=sa;Pwd=sapass!;数据库=mydb;"-dest:dbfullsql="Data Source=.\mydestsource;Integrated Security=false;User ID=sa;Pwd=sapass!;Database=mydb;",computername=10.10.10.10,username=administrator,password=adminpass"
这招对我很管用:
& 'D:\Server\PSTools\PsExec.exe' @('\\1.1.1.1', '-accepteula', '-d', '-i', $id, '-h', '-u', 'domain\user', '-p', 'password', '-w', 'C:\path\to\the\app', 'java', '-jar', 'app.jar')
只需将路径或连接字符串放在一个数组项中,并将其他内容分别分割到一个数组项中。
这里还有很多其他选项:https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx
微软应该让这种方法更简单,并与命令提示符语法兼容。
这招对我很管用:
PowerShell.exe -Command "& ""C:\Some Script\Path With Spaces.ps1"""
关键似乎是整个命令都用外引号括起来,“&”&用于指定正在执行的另一个子命令文件,然后最后在路径/文件名周围转义(双-双-)引号,其中有空格。
这也是MS连接问题的唯一解决方案,即-File不传递非零返回码,而-Command是唯一的替代方案。但到目前为止,人们认为-Command的一个限制是它不支持空格。我也更新了反馈内容。
http://connect.microsoft.com/PowerShell/feedback/details/750653/powershell-exe-doesn-t-return-correct-exit-codes-when-using-the-file-option