这个新建的PSDrive命令
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop导致错误
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我试过先断开所有驱动器,然后再创建新驱动器,
net use * /delete /y
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop我得到了输出
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驱动器
Remove-PSDrive -name Z
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop并得到错误
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
发布于 2015-03-15 09:22:26
我找到了解决这个问题的方法,似乎总是有效的。您需要更改计算机名称,但由于这也将最终停止使用服务器名称和IP,因此您需要选择指定解析到同一台计算机的任意数目的新计算机名。
最明显的选择是hosts文件。您可以将任意数量的别名添加到IP中。之后,使用尚未被阻止的别名。
====编辑===
下面是一个方便的功能:
<# 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")
}在脚本开始时这样做:
$PathAlias = Set-UncHostnameAlias $Path然后与New-PSDrive一起使用别名路径。即使同一系统上的其他脚本对同一台服务器使用不同的凭据,这也总是有效的。
发布于 2020-05-12 14:29:14
我对本地脚本也有同样的问题,发现这是一个简单的解决方案。Get-CimInstance返回所有映射的网络连接,然后将其传递给net /delete /y命令。
$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!"
}发布于 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开始。
https://stackoverflow.com/questions/25995858
复制相似问题