DEV Community

Niels Swimburger.NET ๐Ÿ”
Niels Swimburger.NET ๐Ÿ”

Posted on • Originally published at swimburger.net on

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

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 (0)