3

I am running a powershell based multithreaded application in which each thread (.net task) needs to copy a bunch of files from one machine to another with a different credential. This is the script which runs in each .net task

New-PSDrive -Name tid -PSProvider FileSystem -Root \\sname\c$\Users\<Uname>\Appdata\Local\temp\<myapp>\tid -Credential $cred
Copy-Item -Source c:\test\* tid:\
Remove-PSDrive -Name tid

At any point there could be a bunch of tasks executing this script. Most of the time it works fine, the files are copied. Once in a while I see this error in mapping the network drive:

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again

For testing purposes all my tasks were given the same credential. Can't explain why this error doesn't occur everytime if it is an issue with multiple connections as the error string says.

Ran 20 parallel scripts 15 times (a total of 300 times) and saw this error 6 times. Can someone explain the reason for this and how should this be addressed,

Liam
  • 27,717
  • 28
  • 128
  • 190
Madhulika
  • 283
  • 3
  • 11
  • You admit to using different credential sets. Windows will not allow different credentials to the same destination. I sometimes got around this by designating the FQDN and IP address as mapped drives. Windows saw those as two different destinations. Have to find a technical reference. – Matt May 09 '15 at 22:04
  • Thank you Matt. It seems that using different credentials to map to the same server is not an option. https://connect.microsoft.com/PowerShell/feedback/details/751536/new-psdrive-connection-fails. Strange that I saw the issue intermittently with the same credential too. It just means that copy-item cannot be used in an automated environment where different users can choose to do remote copies. – Madhulika May 10 '15 at 02:50

2 Answers2

0

I had similar error message. Below is my history and solution. So yesterday I created new PS-Drive

$c = Get-Credential
$Drive = new-PSDrive -Name "MyDrive" -PSProvider FileSystem -Root "\\10.11.22.100\LogShare" -Credential $c -Scope global

after that I successfully being using "MyDrive"

Like

get-childItem -path  "MyDrive:\"

Today, after restart the PC, tried again

get-childItem -path  "MyDrive:\"

but got

Get-ChildItem : Cannot find drive. A drive with the name 'MyDrive' does not exist.

Tried to create drive again:

$c = Get-Credential
$Drive = new-PSDrive -Name "MyDrive" -PSProvider FileSystem -Root "\\10.11.22.100\LogShare" -Credential $c -Scope global

Now got

new-PSDrive : Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again

As a solution, I removed -Credential $c from New-PSDrive command and it worked.

Powershell somehow remembers credentials and does not let to connect to shared drive with same creds

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
Viktor Fursov
  • 123
  • 1
  • 8
0
  • Please put to the console (in the same user context if the drive is not persistent)

    net use

to obtain the remote share name.

  • and then

    net use \machine_or_IP\share /delete

to remove existing connection.

  • Remove the drive using Remove-PSDrive
  • Remap the drive afterwards New-PSDrive.
Raf
  • 570
  • 6
  • 13