Skip to content

Instantly share code, notes, and snippets.

@JohnRoos
Created May 29, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnRoos/448dcaf8a62825134d45eeb6645a8295 to your computer and use it in GitHub Desktop.
Save JohnRoos/448dcaf8a62825134d45eeb6645a8295 to your computer and use it in GitHub Desktop.
Convert secure string to plain text
function ConvertSecureToString
{
[CmdletBinding()]
[OutputType([String])]
param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=0)]
[ValidateNotNull()]
[SecureString]
$SecureString
)
Process
{
try {
$binaryString = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($binaryString)
} catch {
Throw "Could not convert secure string to plain text: $($_.Exception.Message)"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment