Encrypt password with key using PowerShell

Encrypt password with key using PowerShell.

One major issue that I had to overcome, was to hide the password for the scripts that I will use them on schedule and there will be no need to include it as clear text. Using the below I was able to encrypt the password of the user that I will use in a script and retrieve it within the script whenever is needed. 

$File = "C:\Scripts\Password.txt"
$Key = (1..32)
$Password = Read-Host -AsSecureString "Enter the password"
$Password | ConvertFrom-SecureString -Key $key | Out-File $file