Powershell Unable to Pass SecureString as Variable

I am trying to Unlock an AD Account via Invoke Powershell script activity. my process is like

  1. Ask User for UserID and Store that value in a variable
  2. Get Credentials From Orchestrator
  3. Invoke Powershell Script with System Admin Domain account(Only system Admin has access to AD). I am using below script

“$credential = New-Object System.Management.Automation.PsCredential($UserName, (ConvertTo-SecureString $Password -AsPlainText -Force))
Unlock-ADAccount -Identity $UserID -Credential $credential”

I am passing the UserName, Password and UserID variable via PowerShellVariables.

** As you guys know if you use Get Credential activity to get Credentials from Orchestrator it converted the Password data type to SecureString. If I pass the Password variable with SecureString data type then Powershell throws an error. If the data type is String then everything works fine**

hi @MartianxSpace

use below expression to convert securestring to normal string

strPassword = new System.Net.NetworkCredential(string.Empty, securePassword).Password

in the above expression replace securePassword with your secure string variable then resultant string you can pass in the powershell script


1 Like

@Ajju Thanks, man. It worked like charm.

1 Like

@MartianxSpace welcome…

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.