如何在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
微软应该让这种方法更简单,并与命令提示符语法兼容。
我有以下代码在我的笔记本电脑上完美地工作:
& $msdeploy `
-source:package="$publishFile" `
-dest:auto,computerName="$server",includeAcls="False",UserName="$username",Password="$password",AuthType="$auth" `
-allowUntrusted `
-verb:sync `
-enableRule:DoNotDeleteRule `
-disableLink:AppPoolExtension `
-disableLink:ContentExtension `
-disableLink:CertificateExtension `
-skip:objectName=filePath,absolutePath="^(.*Web\.config|.*Environment\.config)$" `
-setParam:name=`"IIS Web Application Name`",value="$appName"
然后,当我试图直接在一台服务器上运行时,我开始得到这些错误“无法识别的参数……等....所有参数必须以“-”开头。
在尝试了所有可能的解决方案(没有成功)后,我发现服务器(Windows 2008 R2)上的Powershell是3.0版本,而我的笔记本电脑是5.0版本。(你可以使用“$PSVersionTable”查看版本)。
升级Powershell到最新版本后,它又开始工作了。
这招对我很管用:
& '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
微软应该让这种方法更简单,并与命令提示符语法兼容。