Private/ConvertFrom-KB4SecureString.ps1

function ConvertFrom-KB4SecureString
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [securestring] $SecureString
    )

    $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)

    try
    {
        [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
    }
    finally
    {
        # Clear unmanaged memory after briefly converting the token for the header.
        if ($bstr -ne [IntPtr]::Zero)
        {
            [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
        }
    }
}