net use * /delete /y doesn’t resolve error “New-PSDrive : Multiple connections to a server ….”

Question:

This New-PSDrive command

Causes the error

I have tried disconnecting all drives first, then creating new drive,

I get the output

I also tried removing the Z drive first

And get error

How to fix?

UPDATE

I even rebooted the machine and changed the drive name, but I still get the same error of “New-PSDrive: Multiple connections ……”

UPDATE 2

I have also tried using IP address instead of computer name, but that doesn’t work either, http://support.microsoft.com/kb/938120

Answer:

I found workaround to this problem that seem to always work. You need to change the computer name, but since this will also stop working eventually just as with server name and IP, you need the option to specify arbitrary number of new computer names resolving to the same computer.

The obvious choice is hosts file. You can add any number of aliases to the IP to it. Afterwards, use the alias that isn’t already blocked.

==== EDIT ===

Here is the handy function:

and used aliased path afterwards with the New-PSDrive. This works always, even if some other scripts on the same system use different credentials for the same server.

Source:

net use * /delete /y doesn't resolve error "New-PSDrive : Multiple connections to a server ...." by licensed under CC BY-SA | With most appropriate answer!

$hostEntry = Get-HostEntry $remote_alias* -ea 0 | ? { $_.Comment -eq $remote_hostname } | select -First 1
if (!$hostEntry) {
$remote_alias += (Get-HostEntry $remote_alias*).Count + 1
Write-Verbose "Adding alias $remote_alias => $remote_hostname"
$remote_ip = Test-Connection -ComputerName $remote_hostname -Count 1 | % IPV4Address | % IPAddressToString
Add-HostEntry -Name $remote_alias -Address $remote_ip -Force -Comment $remote_hostname | Out-Null
} else {
$remote_alias = $hostEntry.Name
Write-Verbose "Using $remote_hostname alias: $remote_alias"
}

$UncPath.Replace("\\$remote_hostname", "\\$remote_alias")
}
Do this on the start of the script:

and used aliased path afterwards with the New-PSDrive. This works always, even if some other scripts on the same system use different credentials for the same server.

Source:

net use * /delete /y doesn’t resolve error “New-PSDrive : Multiple connections to a server ….” by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply