2020-12-10

PowerShell Save Credential to file for futher use

Section 1: Create Password File

# Get Password
$PassWord = Read-Host -Prompt 'Please Enter Password';

# Convert to System.Security.SecureString
$PassWord = ConvertTo-SecureString -String 
$PassWord -AsPlainText -Force

# Encrypt it
$Encrypted = ConvertFrom-SecureString -SecureString $Password

# Save to File
$Encrypted | Set-Content Encrypted.txt
Section 2: Read Password File
# Read From File and Convert to System.Security.SecureString
$Password = Get-Content Encrypted.txt | ConvertTo-SecureString

沒有留言:

張貼留言