use*_*092 8 powershell network-drive powershell-2.0 net-use
用户具有读取共享的适当权限,并且共享映射正确.这个问题似乎只发生在PowerShell v2.0中.
如果删除所有映射的驱动器,请重新映射一个驱动器,然后运行Test-Path:
net use /delete * /y
net use G: \\somefileserver\share
Test-Path G:\
Run Code Online (Sandbox Code Playgroud)
Test-Path返回False,即使驱动器已清晰映射,我也可以通过Windows资源管理器访问它.
如果我关闭PowerShell会话并打开一个新会话,Test-Path将返回True,就像它应该的那样.关于(A)的任何想法:可能导致这种情况的原因,以及如何使其正常工作?或(B):除了Test-Path之外,还有另一种方法可以测试网络驱动器的存在吗?我正在尝试编写一个登录脚本来映射用户的网络驱动器,这种行为让我感到疯狂.
Tre*_*van 10
如果Test-Path
cmdlet确实是错误的,那么我建议Exists()
在System.IO.Directory
.NET类上使用该方法.
[System.IO.Directory]::Exists('G:\'); # This returns $true for me
Run Code Online (Sandbox Code Playgroud)
小智 10
我觉得我找到了答案:
Test-Path $('filesystem::\\Server\share$\install.wim')
Run Code Online (Sandbox Code Playgroud)
小智 6
要验证UNC,请使用:
[bool]([System.Uri]$path).IsUnc
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29498 次 |
最近记录: |