Here is the fastest and easiest way to store, “as secure as possible”, Credentials in a XML File.
Get-Credential | Export-Clixml -Path "$Path\Credentials.xml"
Alternativly, you can also use Read-Host to prompt for input.
$UserName = Read-Host 'Enter Username' $Password = Read-Host 'Enter Password' -AsSecureString New-Object System.Management.Automation.PSCredential ($UserName, $Password) | Export-Clixml -Path "$Path\Credentials.xml"
The stored password can be revised only by using the account and the computer that was used to create the XML file.