I am switching user in powershell script
# password is secret variable from azure devops pipeline
$username = 'user2'
$password = convertto-securestring $env:password -AsPlainText -Force
Note: it work for normal string and it wont work for secure variable string
I am getting below error:
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At D:\azdo\_work\_temp\cb1ff41e-8df7-48b7-bc48-f23f47d47b8a.ps1:9 char:36
+ $password = convertto-securestring $env:password -AsPlainText ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSe
cureStringCommand
ansible_passwordin your context and then, it's evaluated as$null$env:password = 'MyPassword'?password, that's why it's null