Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Converts a SecureString to Plain Text
- .DESCRIPTION
- The ConvertFrom-SecureToPlainText converts a SecureString to Plain Text
- .PARAMETER SecurePassword
- The SecureString that is to be converted
- .INPUTS
- System.Security.SecureString. Reqires the SecureString to convert from.
- .OUTPUTS
- System.String. ConvertFrom-SecureToPlainText returns the plain text version of the SecureString
- .EXAMPLE
- ConvertFrom-SecureToPlainText $SecurePassword
- .EXAMPLE
- $SecurePassword = Read-Host -AsSecureString "Please enter your Password"
- $PlainTextPassword = ConvertFrom-SecureToPlainText $SecurePassword
- .LINK
- ConvertFrom-SecureToPlainText
- .LINK
- Source: http://www.powershelladmin.com/wiki/Powershell_prompt_for_password_convert_securestring_to_plain_text
- #>
- Function ConvertFrom-SecureToPlainText
- {
- param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)][System.Security.SecureString] $SecurePassword )
- # Create a "password pointer"
- $PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
- # Get the plain text version of the password
- $PlainTextPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)
- # Free the pointer
- [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
- # Return the plain text password
- Write-Output $PlainTextPassword
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement