# Step 1 - Exporting SecureString from Plain text
"P@ssword1" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Temp 2\Password.txt"
# Step 2 - Creating PSCredential object
$User = "MyUserName"
$File = "C:\Temp 2\Password.txt"
$MyCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)
# The Default Execution Policy is set to restricted, you can see it by typing:
Get-ExecutionPolicy
# You should type the following to make it go to unrestricted mode:
Set-ExecutionPolicy unrestricted