Setup: A computer with PowerShell
Problem: You need to run scripts which require credentials, unattended. You can store the password on the disk and load at runtime.
Run this command to create a file to store the password
read-host -AsSecureString | ConvertFrom-SecureString | Set-Content c:\secure.txt
Add these in your script to create a credential object at runtime:
$password = type C:\secure.txt | ConvertTo-SecureString $credential= New-Object -TypeName System.Management.Automation.PSCredential -argumentlist "username",$password