Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
断开Powershell中特定服务器映射的连接_Powershell_Powershell 2.0 - Fatal编程技术网

断开Powershell中特定服务器映射的连接

断开Powershell中特定服务器映射的连接,powershell,powershell-2.0,Powershell,Powershell 2.0,我们遇到了一个问题,服务器组推出了不正确的驱动器映射,导致多个连接(具有不同的驱动器号)到同一台服务器。包含以下内容的批处理文件修复了此问题: for /f "tokens=2,3" %%a in ('net use') do if .%%b==.\\Ncprolawapp01\ProLaw net use %%a /Delete for /f "tokens=2,3" %%a in ('net use') do if .%%b==.\\Ncatsqlapp01\ProLaw net use %

我们遇到了一个问题,服务器组推出了不正确的驱动器映射,导致多个连接(具有不同的驱动器号)到同一台服务器。包含以下内容的批处理文件修复了此问题:

for /f "tokens=2,3" %%a in ('net use') do if .%%b==.\\Ncprolawapp01\ProLaw net use %%a /Delete
for /f "tokens=2,3" %%a in ('net use') do if .%%b==.\\Ncatsqlapp01\ProLaw net use %%a /Delete
net use R: \\NCPROLAWAPP01\PROLAW

我现在要做的是将其放入Powershell脚本中,以便在将来的映像上的首次用户设置中运行。我没有时间查找太多,但我知道上面的行在Powershell中无法运行。只是想寻求一些建议。

如果已经有这样一个驱动器映射到您的服务器,您可以使用wmi进行检查:

PS>get-wmiObject "win32_logicalDisk" |where-object {$_.ProviderName -eq "\\Ncprolawapp01\ProLaw"}


DeviceID     : Z:
DriveType    : 4
ProviderName : \\Ncprolawapp01\ProLaw
FreeSpace    : 298465705984
Size         : 644245090304
VolumeName   :
您可以使用旧的“网络使用/d”断开驱动器的连接

PS>gwmi "win32_logicalDisk" |? {$_.ProviderName -eq "\\Ncprolawapp01\ProLaw"} |%{ net use $_.DeviceID /delete}
Z: a été supprimé.