Created
May 29, 2017 18:15
-
-
Save JohnRoos/448dcaf8a62825134d45eeb6645a8295 to your computer and use it in GitHub Desktop.
Convert secure string to plain text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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