Create the Encrypted FileFirst create the encrypted text file by running the following:
$cred = Get-Credential
$cred.Password | ConvertFrom-SecureString | Out-File .\adcreds.txt
Using the Encrypted CredentialsTo use the credential file in powershell you can use:
$User = "firstname.lastname@example.org"
$File = "C:\Development\Vivity\adcreds.txt"
$cred = New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)