Password in Powershell Script #004
Password in Powershell Script #004
by
Kevin
·
Published
· Updated
### Step 1: Creating Securestring encrypted with AES Key
$AESKey = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($AESKey)
$AESKey | Out-File .\Desktop\aes.key
$password = Read-Host -AsSecureString
$password | ConvertFrom-SecureString -Key $AESKey | Out-File .\Desktop\password.txt
### Step 2: Using Securestring and AES Key in Scripts
$username = "Administrator"
$AESKey = Get-Content .\Desktop\aes.key
$password = Get-Content .\Desktop\password.txt | ConvertTo-SecureString -Key $AESKey
$credentials = New-Object System.Management.Automation.PSCredential (“$username”, $password)
You may also like...