MSBuild使用凭据调用Powershell [英] MSBuild calling Powershell with credentials

查看:97
本文介绍了MSBuild使用凭据调用Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用运行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' "

有适当的方法吗?

推荐答案

使用首先在与要运行构建的同一台计算机上的同一用户进行定期会话中保存凭据. (好吧,在每台这样的机器和用户配置文件上.)然后,在构建脚本中,从同一路径导入Import-Credential,并将新的$ cred传递给Invoke-Command.

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屋!

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