Post

Create Secure Password File

Method 1

1
2
$MyCredentials=GET-CREDENTIAL -Credential "USERNAME" | EXPORT-CLIXML C:\Temp\SecureCredentials.xml
$MyCredentials=IMPORT-CLIXML C:\Temp\SecureCredentials.xml

Method 2

To create the file run the below

1
2
$credential = Get-Credential
$credential.Password | ConvertFrom-SecureString | Set-Content c:scriptsencrypted_password1.txt

To use the file

1
2
3
$usename = "myemail"
$encrypted = Get-Content c:scriptsencrypted_password.txt | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential($usename, $encrypted)
This post is licensed under CC BY 4.0 by the author.