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

发布于 2024-07-06 07:51:39 字数 1232 浏览 8 评论 0原文

在 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.

Get-PSDrive 告诉我们根目录是 H:

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

Name       Provider      Root      CurrentLocation
----       --------      ----      ---------------
H          FileSystem    H:\          temp

并且使用 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:\

关于如何获取的任何想法那个信息?

谢谢

In PowerShell, even if it's possible to know if a drive is a network drive: see In PowerShell, how can I determine if the current drive is a networked drive or not?

When I try to get the "root" of the drive, I get back the drive letter.

The setup:
MS-Dos "net use" shows that H: is really a mapped network drive:

New connections will be remembered.

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

The command completed successfully.

Get-PSDrive tells us that the Root is H:

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

Name       Provider      Root      CurrentLocation
----       --------      ----      ---------------
H          FileSystem    H:\          temp

and using system.io.driveinfo does not give us a complete answer:

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:\

Any idea of how to get that info?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

赠意 2024-07-13 07:51:39

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

(Get-PSDrive h).DisplayRoot

The trick is that the attribute name is different than expected.
Try:

(Get-PSDrive h).DisplayRoot

浅笑轻吟梦一曲 2024-07-13 07:51:39

尝试WMI:

Get-WMIObject -query "Select ProviderName From Win32_LogicalDisk Where DeviceID='H:'"

Try WMI:

Get-WMIObject -query "Select ProviderName From Win32_LogicalDisk Where DeviceID='H:'"
半寸时光 2024-07-13 07:51:39

$drive = gwmi win32_ologicaldisk -filter "DeviceID='H:'"
if($drive.DriveType -eq 4) {write-host "驱动器是网络共享"}

$drive = gwmi win32_logicaldisk -filter "DeviceID='H:'"
if($drive.DriveType -eq 4) {write-host "drive is a network share"}

长发绾君心 2024-07-13 07:51:39

$fso=new-object -com "Scripting.Filesystemobject"
$fso.GetDrive("Y").ShareName

$fso=new-object -com "Scripting.Filesystemobject"
$fso.GetDrive("Y").ShareName

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文