我想使用Test-Path和Resolve-Path测试文件共享上是否存在子文件夹。首先,我在我的机器\ someshare \ somefolder上创建一个共享。然后使用文件浏览器我添加一个子文件夹,所以整个路径如下所示:\ someshare \ somefolder \ subfolder
Test-Path \\server\someshare results in True
Test-Path \\server\someshare\subfolder results in False
Resolve-Path \\server\someshare results in True
Revolve-Path \\server\someshare\subfolder results in does not exist error
为什么powershell不会为子文件夹返回true?
答案 0 :(得分:1)
我无法重新创建你说你得到的结果,但我会注意到你所呈现的UNC似乎已经关闭了。 UNC通常是\ server \ share \文件夹。您好像省略了服务器名称。有没有机会在网络上实际上有一台机器与你用于共享的机器具有相同的名称,那就是你正在测试的那个?
更新:你说你已经创建了\ server \ someshare \ somefolder,然后将\ subfolder添加到路径中。您正在测试\ server \ someshare \子文件夹。假设您对文件夹创建的描述准确无误,那么您应该测试\ server \ someshare \ somefolder \子文件夹。
答案 1 :(得分:1)
这里没有问题,听起来像权限,尝试以管理员身份连接?
& "net" "use" "\\192.168.1.1\psinstall" "password" "/USER:domain\username"
Test-Path "\\192.168.1.1\psinstall\app"
Test-Path "\\192.168.1.1\psinstall\app\subfolder"
Resolve-Path "\\192.168.1.1\psinstall\app"
Resolve-Path "\\192.168.1.1\psinstall\app\subfolder"
& "net" "use" "\\192.168.1.1\psinstall" "/delete"
& "net" "use" "\\192.168.1.1\c$\psinstall" "password" "/USER:domain\username"
Test-Path "\\192.168.1.1\c$\psinstall\app"
Test-Path "\\192.168.1.1\c$\psinstall\app\subfolder"
Resolve-Path "\\192.168.1.1\c$\psinstall\app"
Resolve-Path "\\192.168.1.1\c$\psinstall\app\subfolder"
& "net" "use" "\\192.168.1.1\c$\psinstall" "/delete"