在 PowerShell 中,如何确定驱动器的根目录(假设它是网络驱动器)

JJa*_*ava 1 powershell networking mapped-drive

在 PowerShell 中,即使可以知道驱动器是否为网络驱动器:请参阅在 PowerShell 中,如何确定当前驱动器是否为网络驱动器?

当我尝试获取驱动器的“根”时,我得到了驱动器号。

设置:MS-Dos "net use" 显示 H: 实际上是一个映射的网络驱动器:

New connections will be remembered.

Status       Local     Remote                    Network
-------------------------------------------------------------------------------
OK           H:        \\spma1fp1\JARAVJ$        Microsoft Windows Network

The command completed successfully.
Run Code Online (Sandbox Code Playgroud)

Get-PSDrive 告诉我们 Root 是 H:

PS:24 H:\temp
>get-psdrive  h

Name       Provider      Root      CurrentLocation
----       --------      ----      ---------------
H          FileSystem    H:\          temp
Run Code Online (Sandbox Code Playgroud)

使用 system.io.driveinfo 并没有给我们一个完整的答案:

PS:13 H:\
>$x = new-object system.io.driveinfo("h:\")
PS:14 H:\
>$x.DriveType
Network
PS:15 H:\
>$x.RootDirectory

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        29/09/2008     16:45            h:\
Run Code Online (Sandbox Code Playgroud)

知道如何获取这些信息吗?

谢谢

小智 6

诀窍是属性名称与预期不同。尝试:

(Get-PSDrive h).DisplayRoot