Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将秘密变量从TFS生成传递到Powershell脚本_Powershell_Tfsbuild_Continuous Deployment - Fatal编程技术网

将秘密变量从TFS生成传递到Powershell脚本

将秘密变量从TFS生成传递到Powershell脚本,powershell,tfsbuild,continuous-deployment,Powershell,Tfsbuild,Continuous Deployment,我在构建定义中添加了名为Password的秘密变量,如下图所示: 我想在构建步骤之一中将密码传递给PowerShell脚本,如下图所示: 我的PowerShell脚本如下所示 Param ( [Parameter(Mandatory=$true)] [string]$UserName, [Parameter(Mandatory=$true)] [string]$Password ) $appPool = New-WebAppPool -Name "test

我在构建定义中添加了名为Password的秘密变量,如下图所示:

我想在构建步骤之一中将密码传递给PowerShell脚本,如下图所示:

我的PowerShell脚本如下所示

 Param
(
    [Parameter(Mandatory=$true)]
    [string]$UserName,
    [Parameter(Mandatory=$true)]
    [string]$Password
)

$appPool = New-WebAppPool -Name "test"
$appPool.processModel.userName = $userName
$appPool.processModel.password = $password
$appPool.processModel.identityType = "SpecificUser"
$appPool | Set-Item

但看起来密码的类型不是字符串。我尝试了PSCredential,但没有成功。有人能帮我吗?如何将密码从构建步骤传递到PowerShell脚本以及安全变量的类型?我无法直接读取环境变量,因为我正在目标计算机上运行PowerShell脚本。因此,唯一的选择是将密码作为输入传递给脚本。

最后我设法解决了这个问题

通过powershell脚本参数发送密码时,我在密码周围加了双引号。繁荣它开始工作了。它发送解密的密码

-用户名$(用户名)-密码“$(密码)”

我的powershell脚本与上面的相同

 Param
(
    [Parameter(Mandatory=$true)]
    [string]$UserName,
    [Parameter(Mandatory=$true)]
    [string]$Password
)

$appPool = New-WebAppPool -Name "test"
$appPool.processModel.userName = $userName
$appPool.processModel.password = $password
$appPool.processModel.identityType = "SpecificUser"
$appPool | Set-Item

请尝试
$appPool.processModel.password=(ConvertTo SecureString-Force-AsPlainText$password)
机密变量将被解密以供构建步骤访问。因此,您可以在密码参数中使用它们。您在构建过程中是否遇到任何错误?我已经测试了你的脚本,没有出现问题。但是这个语句不起作用$appPool.processModel.password=(ConvertTo SecureString-Force-AsPlainText$password)。它的值为System.Security.SecureString,但不是实际密码。因此,apppool没有设置正确的密码。它不知道如何解密。”“没有为我改变任何事情。在2018年TFS中,它似乎以同样的方式使用或不使用“”。我仍然想知道为什么我不能在param部分使用“[SecureString]$Password”。