2008-10-01 32 views
1

在PowerShell中,即使有可能知道,如果一个驱动器是一个网络驱动器:看In PowerShell, how can I determine if the current drive is a networked drive or not?在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:\ 

如何GE的任何想法那个信息?

由于

回答

0

尝试WMI:

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

A小调挑剔,它的获取 - WmiObject可以代替GET-WMI :) – JJarava 2008-10-01 16:39:42

0

$驱动= gwmi的Win32_LogicalDisk筛选器 “的DeviceID = 'H:'” 如果($ drive.DriveType -eq 4){写主机“驱动器是网络共享 “}

0

$ FSO =新物体-com ”Scripting.FileSystemObject的“ $ fso.GetDrive(” Y“)。共享名

3

诀窍在于,所述贡品名与预期不同。 尝试:

(Get-PSDrive h).DisplayRoot