Open patware opened 5 years ago
Found it… I was super close….. For the ConverTo-SecureString, I had to wrap the deploymentPassword with double quotes:
My suggestion is to add this to your Knowledge Base/Wiki/Readme.md for others.
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
Write-Host "Securing value" $secpasswd = ConvertTo-SecureString "$(deploymentPassword)" -AsPlainText -Force
Write-Host "Creating the Credential Object" $cred = New-Object -TypeName "System.Management.Automation.PSCredential"( "myDomain\myUser", $secpasswd )
I'm trying to figure how to use a "Secret" variable with the PowerShell++ Inline Script.
Is it possible ?
Here's what I tried so far.
The secret variable is named deploymentPassword
Test 1:
Write-Host "Encrypting the Password" $secpasswd = ConvertTo-SecureString $(deploymentPassword) -AsPlainText -Force
Write-Host "Creating the Credential Object" $cred = New-Object -TypeName "System.Management.Automation.PSCredential"( "TENANTDEV\SVC-TFS-DV-DEPLOY", $secpasswd )
I get this error: Encrypting the Password
[error]Cannot process command because of one or more missing mandatory parameters: String.
Test 2:
Write-Host "Encrypting the Password" $secpasswd = ConvertTo-SecureString $(deploymentPassword) -Force
Write-Host "Creating the Credential Object" $cred = New-Object -TypeName "System.Management.Automation.PSCredential"( "TENANTDEV\SVC-TFS-DV-DEPLOY", $secpasswd )
I get this error: Encrypting the Password
[error]Cannot process command because of one or more missing mandatory parameters: String.
Test 3:
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
Write-Host "Reading from TFS Variable" $password = Get-TaskVariable -Context $distributedTaskContext -Name "deploymentPassword"
Write-Host "Creating the Credential Object" $cred = New-Object -TypeName "System.Management.Automation.PSCredential"( "TENANTDEV\SVC-TFS-DV-DEPLOY", $password )
I get this error: Creating the Credential Object
[error]Cannot find an overload for "PSCredential" and the argument count: "2".
Test 4:
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
Write-Host "Reading from TFS Variable" $password = Get-TaskVariable -Context $distributedTaskContext -Name "deploymentPassword"
Write-Host "Securing value" $secpasswd = ConvertTo-SecureString $(deploymentPassword) -AsPlainText -Force
Write-Host "Creating the Credential Object" $cred = New-Object -TypeName "System.Management.Automation.PSCredential"( "TENANTDEV\SVC-TFS-DV-DEPLOY", $secpasswd )
I get this error: Securing value
[error]Cannot process command because of one or more missing mandatory parameters: String.