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

时间:2008-10-01 16:33:09

标签: powershell networking mapped-drive

在PowerShell中,即使可以知道驱动器是否是网络驱动器:请参阅In PowerShell, how can I determine if the current drive is a networked drive or not?

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

设置: 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告诉我们Root是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:\

有关如何获取该信息的任何想法吗?

由于

4 个答案:

答案 0 :(得分:4)

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

(Get-PSDrive h).DisplayRoot

答案 1 :(得分:0)

尝试WMI:

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

$ fso = new-object -com“Scripting.Filesystemobject” $ fso.GetDrive( “Y”)。共享名