首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >net use * /delete /y不解析错误“New:到服务器的多个连接.”

net use * /delete /y不解析错误“New:到服务器的多个连接.”
EN

Stack Overflow用户
提问于 2014-09-23 13:03:53
回答 6查看 11.9K关注 0票数 5

这个新建的PSDrive命令

代码语言:javascript
复制
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop

导致错误

代码语言:javascript
复制
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

我试过先断开所有驱动器,然后再创建新驱动器,

代码语言:javascript
复制
net use * /delete /y
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop

我得到了输出

代码语言:javascript
复制
You have these remote connections:
                \\TSCLIENT\C
                \\TSCLIENT\D
                \\TSCLIENT\E
                \\TSCLIENT\I
                \\TSCLIENT\J
                \\TSCLIENT\K
                \\TSCLIENT\L
                \\TSCLIENT\R
                \\TSCLIENT\T
Continuing will cancel the connections.

The command completed successfully.

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

我还试着先移除Z驱动器

代码语言:javascript
复制
Remove-PSDrive -name Z
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop

并得到错误

代码语言:javascript
复制
Remove-PSDrive : Cannot find drive. A drive with the name 'Z' does not exist.
...
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

怎么修?

更新

我甚至重新启动了机器并更改了驱动器名,但是我仍然得到了相同的错误“New:.”

更新2

我也尝试过使用IP地址而不是计算机名,但这也不起作用,http://support.microsoft.com/kb/938120

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2015-03-15 09:22:26

我找到了解决这个问题的方法,似乎总是有效的。您需要更改计算机名称,但由于这也将最终停止使用服务器名称和IP,因此您需要选择指定解析到同一台计算机的任意数目的新计算机名。

最明显的选择是hosts文件。您可以将任意数量的别名添加到IP中。之后,使用尚未被阻止的别名。

====编辑===

下面是一个方便的功能:

代码语言:javascript
复制
<#  Use unique hostname for this script by altering hosts table to handle situation with multiple different scripts 
    using this share with different creds which leads to following Windows error: 

    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

    #require -RunAsAdministrator
    #require -module PsHosts

    https://stackoverflow.com/a/29059100/82660 
#>
function Set-UncHostnameAlias($UncPath) {
    $remote_hostname = $UncPath -split '\\' | ? {$_} | select -First 1
    $remote_alias    = (Split-Path -Leaf $MyInvocation.ScriptName) -replace '.ps1$'

    $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")
}

在脚本开始时这样做:

代码语言:javascript
复制
$PathAlias = Set-UncHostnameAlias $Path

然后与New-PSDrive一起使用别名路径。即使同一系统上的其他脚本对同一台服务器使用不同的凭据,这也总是有效的。

票数 2
EN

Stack Overflow用户

发布于 2020-05-12 14:29:14

我对本地脚本也有同样的问题,发现这是一个简单的解决方案。Get-CimInstance返回所有映射的网络连接,然后将其传递给net /delete /y命令。

代码语言:javascript
复制
$shareDrives = Get-CimInstance -ClassName Win32_NetworkConnection

if ($shareDrives -ne $null)
{
    foreach ($shareDrive in $shareDrives)
    {
        Write-Host "`nRemoving mapped drive $($shareDrive.LocalName)"
        net use $shareDrive.LocalName /delete /y
    }
}
else
{
    Write-Host "`nNo mapped drives to remove!" 
}
票数 2
EN

Stack Overflow用户

发布于 2015-05-21 20:38:06

使用FQND对我有用..。

如何找出FQDN??

ping -a -n 1

这是FQND! 192.168.0.1,有32个字节的答复,从192.168.0.1: bytes=32 time=1ms TTL=128开始。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25995858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档