Skip to content

PowerShell++ inline script and Secret Variables #100

Description

@patware

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions