Skip to content

Instantly share code, notes, and snippets.

@Swimburger
Created November 2, 2020 22:30
Show Gist options
  • Save Swimburger/663cf785236c4d9e7294bfc1ae87716c to your computer and use it in GitHub Desktop.
Save Swimburger/663cf785236c4d9e7294bfc1ae87716c to your computer and use it in GitHub Desktop.
A function to convert secure string to plain text as a pre-PowerShell 7 alternative
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment