Glo*_*wie 5 powershell remoting drive
这个New-PSDrive命令
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop
Run Code Online (Sandbox Code Playgroud)
导致错误
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
Run Code Online (Sandbox Code Playgroud)
我尝试先断开所有驱动器,然后创建新驱动器,
net use * /delete /y
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop
Run Code Online (Sandbox Code Playgroud)
我得到了输出
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
Run Code Online (Sandbox Code Playgroud)
我也尝试先删除Z盘
Remove-PSDrive -name Z
New-PSDrive -Name Z -PSProvider FileSystem -Root \\$j\share -Credential $credentials -ErrorAction Stop
Run Code Online (Sandbox Code Playgroud)
并得到错误
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
Run Code Online (Sandbox Code Playgroud)
怎么修?
UPDATE
我甚至重新启动了机器并更改了驱动器名称,但我仍然得到"New-PSDrive:多个连接......"的相同错误.
更新2
我也尝试使用IP地址而不是计算机名称,但这也不起作用,http://support.microsoft.com/kb/938120
我找到了解决这个问题的方法,似乎总是有效。您需要更改计算机名称,但由于这最终也会像服务器名称和 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
/sf/answers/2034137031/
#>
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")
}
Run Code Online (Sandbox Code Playgroud)
在脚本的开头执行此操作:
$PathAlias = Set-UncHostnameAlias $Path
Run Code Online (Sandbox Code Playgroud)
并随后使用别名路径New-PSDrive。即使同一系统上的某些其他脚本对同一服务器使用不同的凭据,这也始终有效。
| 归档时间: |
|
| 查看次数: |
6511 次 |
| 最近记录: |