I am using New-PSDrive to map network drives. My issue is that despite using the -Persist and -Scope Global parameters the drives no longer show up at the next Windows login for the user. The drives require credentials to access which I pass into the New-PSDrive command. I can see that the drives still exist after a logout and login by using net use at the command line, but the drives are not available. I believe what might be occurring is that Windows does not store the credentials and therefore cannot reconnect, but the drives do not show in Windows Explorer at all after logout and login. I am looking for a way to persist the drives as if I had created them through the "Map Network Drive" option in Windows File Explorer and checked the "Remember my credentials" option after selecting to use different credentials. Is this possible in Powershell? If not is there another Windows scripting language that would support this functionality? Here is my code:
#iterate through array of connection information and map drives
foreach ($connection in $connections)
{
#split out array into variables
$driveletter,$key,$account,$location = $connection
$acctKey = ConvertTo-SecureString -String $key -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $account, $acctKey
New-PSDrive -Name $driveletter -PSProvider FileSystem -Root $location -Scope Global -Credential $credential -Persist -ErrorAction SilentlyContinue
}