Stokage de mot de passe

Create the Secure String Password

Open a PowerShell session with administrator privileges. First piece is to create a variable and execute Get-Credential to popup a box for us to type in the credentials we need to connect.

$credential = Get-Credential

Next step is to write the secure string to a file for reference. You can change the location where you want to store the password. You will recieve a popup in which you will need to add the DOMAIN\username and password to access the share.

$credential.Password | ConvertFrom-SecureString | Set-Content c:\temp\password.txt

sample usage to mount a network drive

$encrypted = Get-Content c:\temp\password.txt | ConvertTo-SecureString

$credential = New-Object System.Management.Automation.PsCredential("DOMAIN\username_associate_to_pwd", $encrypted)

New-PSDrive -name "G" -PSProvider FileSystem -Root \\SERVER\share -Persist -Credential $credential
Dernière modification: le 2019/11/20