Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mnjstwins/9e7fae7f28b1546ad50d071f6239776f to your computer and use it in GitHub Desktop.
Save mnjstwins/9e7fae7f28b1546ad50d071f6239776f to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment