How To Encrypt Password Using PowerShell

I’d like to describe how to use PowerShell to encrypt a password in a text file in this blog.

I received a requirement that stated we had to encrypt the password in a text file and read that text file in a powershell script in order to establish a connection to SharePoint.

Here is the code to generate password in encrypted format

$password = Read-Host -Prompt "Please enter your password" -AsSecureString
$bytes = ConvertFrom-SecureString $password
$bytes | out-file .\MyPassword.txt

 

When you run this script, a window will appear and ask for a password; simply provide the password you want to encrypt. Press the “OK” button after entering the password. It will create an encrypted password and store it in a text file called MyPassword.txt in the location specified below,

“C:\Umang\POC\PnPEncryptPass”

 

 

Our password is encrypted when we open the text file, and we may use this password-protected file in any script when setting up a sharepoint connection.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories