MSBuild使用凭据调用Powershell [英] MSBuild calling Powershell with credentials
问题描述
我正在尝试使用运行Powershell命令的MSBuild脚本来部署Windows服务.
I'm trying to deploy a windows service using an MSBuild script that runs a Powershell command.
MSBuild脚本将部署我需要的文件,PowerShell脚本将使用以下命令卸载并重新安装Windows服务:
The MSBuild script deploys the files I need and the PowerShell script will uninstall and reinstall the windows service using this command:
Invoke-Command -ComputerName IPAddressHere -FilePath"C:\ theScriptFileName.ps1"-凭据"TheUserName"
Invoke-Command -ComputerName IPAddressHere -FilePath "C:\theScriptFileName.ps1" -credential "TheUserName"
使用IP地址(由于域不同,我需要使用该地址)我需要使用凭据.问题在于它会提示您输入密码,而该密码对TeamCity的自动化不起作用.
Using an IP address (which I need to because of different domains) I need to use credentials. The problem is that it prompts for a password, which won't work for TeamCity's automation.
我知道我可以将凭据保存到变量中,以便提示符不会显示,但是我需要将其放入类似于以下行的内容,MSBuild可以执行以下操作:
I know I can save the credentials into a variable so that the prompt won't show, but I need to get it into a line something like the following that MSBuild can execute:
powershell.exe -NonInteractive -executionpolicy不受限制的-command&调用命令-ComputerName IPAddressHere -FilePath'C:\ theScriptFileName.ps1'"
powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& Invoke-Command -ComputerName IPAddressHere -FilePath 'C:\theScriptFileName.ps1' "
有适当的方法吗?
推荐答案
Save the credentials first in a regular session with the same user on the same machine that will be running the builds. (Well, on each such machine and user profile.) Then, in the build script, Import-Credential from the same path and pass the new $cred to Invoke-Command.
这篇关于MSBuild使用凭据调用Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!