-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConvert-SecureStringToString.ps1
40 lines (34 loc) · 1.16 KB
/
Convert-SecureStringToString.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function Convert-SecureStringToString {
<#
.SYNOPSIS
Converts a SecureString value back to a plaintext string
.DESCRIPTION
Converts a SecureString value back to a plaintext string
.PARAMETER SecureString
The SecureString that you want to get back to being plaintext
.EXAMPLE
$SecureString = Read-Host -Prompt 'Enter a string' -AsSecureString
#Let's say you entered the string 'Password' without quotes
Convert-SecureStringToString -SecureString $SecureString
Password
.NOTES
# inspired by: https://gallery.technet.microsoft.com/Execute-PowerShell-Script-38881dce
#>
[CmdletBinding(ConfirmImpact='Low')]
[OutputType('string')]
Param (
[Parameter(Mandatory)]
[securestring] $SecureString
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
$UserName = 'domain\user'
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, $SecureString
Write-Output -InputObject $Credential.GetNetworkCredential().Password
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}