DEV Community

loading...

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

swimburger profile image Niels Swimberghe Originally published at swimburger.net on ・1 min read

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;
}

Enter fullscreen mode Exit fullscreen mode

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

Discussion

pic
Editor guide