Map a Network Drive with Encrypted Password

The New-PSDrive allows you mount any PSProvider as a drive. This is quite easy and simple. In this article I’ll will explain you how to map a network drive with a encrypted password. First we need to create a secure password string instead of a plain text password string. For security reasons we cannot included this in the script.

Open a new PowerShell window with administrator privileges and create a variable and execute this with Get-Credential. Get-Credential will open a login box. In this login box we type the credentials we needed to connect.

Next thing we do is write the secure string to a file, for example C:\PS\Password.txt. You can change the location to store the password file wherever you want. In case of this article I’ll will use C:\PS\Password.txt. You will see a login box where you need to add the domain\username and password to access the share.

We now ready to continue and make the drive connection using the Secure-String password we setup as described above. First we point the $Encrypted variable to the location of the Secure-String password we setup as described above.

Now we define the $Credential with the encrypted password to connect the share.

Now we can map the drive. Change the -Name parameter to your own drive letter. The -Root parameter should be a UNC path to map the network drive. Change the drive letter to your own, in this example I using M for mapping the drive.

Full Script:

To verify, type Get-PSDrive M or Get-PSDrive cmdlet to see all mounted drives available on your computer.

If you want remove the drive mapping, use the Remove-PSDrive cmdlet, for example:

In this article I explained how to map a network drive with a encrypted password. The New-PSDrive allows you to mount any PSProvider as a drive. To remove the drive mapping, use Remove-PSDrive.

I really like to hear what you have to say about this article:

  • Was this article helpful for you or do you have any questions?
  • Do you have additions, suggestions or any other ideas?
  • Just let me know by leaving a comment below.

Thank you for spending some time at my site and in my blog. I hope you come to visit again soon!

About Lex van der Horst 201 Articles

Be the first to comment

Leave a Reply