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 \\0.0.0.0\AB -Credential $SecureCredential -Persist

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
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?


https://www.experts-exchange.com/dashboard/#/questions/29259406How to map to the same share using 2 different sets of credentials.

Avatar of E=mc2

ASKER

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