Swimburger

ConvertFrom-SecureString : A parameter cannot be found that matches parameter name 'AsPlainText'

Niels Swimberghe

Niels Swimberghe - - PowerShell

Follow me on X, buy me a coffee

If you're using older versions of PowerShell, you do not have the 'AsPlainText' flag available to you. You're not out of luck though, you can quickly create your own function which will give you the same result.

PowerShell 7 introduces a new option AsPlainText to the ConvertFrom-SecureString function. When using this new flag, you receive the plain text version of the secure string. If you're using older versions of PowerShell, you do not have this flag available and the following error is printed:

"ConvertFrom-SecureString : A parameter cannot be found that matches parameter name 'AsPlainText'."

You're not out of luck though, you can quickly create your own function which will give you the same result:

Function ConvertFrom-SecureString-AsPlainText{
    [CmdletBinding()]
    param (
        [Parameter(
            Mandatory = $true,
            ValueFromPipeline = $true
        )]
        [System.Security.SecureString]
        $SecureString
    )
    $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString);
    $PlainTextString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr);
    $PlainTextString;
}

Load this function into memory and simply pass in your secure string to get a plain text version string back.