【发布时间】:2020-02-26 17:32:50
【问题描述】:
我在 powershell 脚本中(在 Jenkins 中)有以下命令:
$Command = "C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe"
$Parms = "/Action:Script /sf:DB.dacpac /Profile:publish.xml"
$Prms = $Parms.Split(" ")
& "$Command" $Prms
如何以其他用户身份运行 SqlPackage.exe?
PS:它在 Jenkins 中,所以我无法使用 runas windows 对话框运行 ps1 文件或 SqlPackage.exe。
编辑:
我想我已经很接近了,到目前为止我有以下脚本。
$sb = [scriptblock]::create("& ""SqlPackage.exe"" ""/Action:Script /sf:DB.dacpac /Profile:publish.xml /TargetServerName:localdb /op:Publish.sql""")
$Secure_Password = ConvertTo-SecureString -String $parPassword -AsPlainText -Force
$Credential = New-Object -Type PSCredential($parUserId,$Secure_Password)
$Session = New-PSSession -ComputerName ServerName -Credential $Credential
Invoke-Command -Session $Session -ScriptBlock $sb
我收到以下错误:
*** 参数 'Action' 的值无效:'Script /sf:DB.dacpac /Profile:publish.xml /TargetServerName:localdb /op:Publish.sql'
【问题讨论】:
-
感谢@gravity。它很相似,但没有回答我如何传递参数。我是 powershell 新手,所以我可能不太清楚。
-
有关参数帮助,请看这里.. 但从技术上讲,这是一个与您原来的问题不同的问题 - stackoverflow.com/questions/16347214/…
-
感谢@gravity。
标签: powershell