In PowerShell, how can I determine the root of a drive (suppose it's a network drive)

In PowerShell, even if you know if the drive is a network drive: see in PowerShell, how to determine if the current drive is a network drive or not?

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

Setting: "Network Usage of MS-Dos" shows that H: really is 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 Root has a value of 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 the full 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 on how to get this information?

thanks

+1
powershell networking mapped-drive
source share
4 answers

Try WMI:

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

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

(Get-PSDrive h).DisplayRoot

+3
source share

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

0
source share

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

0
source share

All Articles