Skip to content

Commit b8cb4de

Browse files
author
Ricky Lee
committed
1.0
1 parent 0797acc commit b8cb4de

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Convert-SecureStringText.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Convert-SecureStringText {
2+
<#
3+
Objective: Convert between plaintext and SecureString text
4+
5+
Version:
6+
1.0 - 2023-22-24 [email protected]
7+
#>
8+
[cmdletbinding()]
9+
param (
10+
[Parameter(Mandatory=$true)]
11+
[ValidateSet("to","from")]
12+
[string]$action,
13+
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
14+
[string]$MyInput
15+
)
16+
17+
Try {
18+
If ($action -eq "to") {
19+
$result = $MyInput.Trim() | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -ErrorAction SilentlyContinue
20+
}
21+
else {
22+
$result = [Net.NetworkCredential]::new('', (($MyInput.Trim()) |ConvertTo-SecureString)).password
23+
}
24+
return $result
25+
}
26+
catch {
27+
Write-Warning "Unable to convert.....`n`n$($_.Exception)"
28+
}
29+
}

0 commit comments

Comments
 (0)