Link to home
Create AccountLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Change PowerShell script to store credentials and then going forward only connect using stored credentials

I would like to change the following script so that first it stores teh credentials and connects.  And I would like to comment out portions so that the next time this is run it only connects using the stored credentials. 

Thanks for your assistance. 

#Prompt the user for credentials and store into a file in encrypted format
$Credential = Get-Credential
$User = $Credential.UserName
$Credential.Password | ConvertFrom-SecureString | Set-Content C:\Screds\Creds.txt
$EncryptedPass = Get-Content C:\Screds\Creds.txt | ConvertTo-SecureString
$SecureCredential = New-Object System.Management.Automation.PsCredential($User,$EncryptedPass)
New-PSDrive -Name "Z" -PSProvider "FileSystem" -Root \\\AB -Credential $SecureCredential -Persist

Open in new window

Avatar of oBdA

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account

Your previous question, is it about the same as what you're asking here? to map to the same share using 2 different sets of credentials.

Avatar of E=mc2


The above script will not accomplish what I am looking for, that is to map the same share using 2 different sets of credentials at the same time..  

That is because you can't do that as the operating system would have no idea of in a per window basis which permissions to apply. 

The easiest way is to run another OS in a virtual machine on the same computer and  then you can copy/paste from one OS to the other