Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell++ inline script and Secret Variables #100

Open
patware opened this issue Jul 25, 2018 · 1 comment
Open

PowerShell++ inline script and Secret Variables #100

patware opened this issue Jul 25, 2018 · 1 comment

Comments

@patware
Copy link

patware commented Jul 25, 2018

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.

@patware
Copy link
Author

patware commented Jul 27, 2018

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.

This worked:

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant