Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PowerShell, how can I determine if the current drive is a networked drive or not?

I need to know, from within Powershell, if the current drive is a mapped drive or not.

Unfortunately, Get-PSDrive is not working "as expected":

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

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

but in 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.

What I want to do is to get the root of the drive and show it in the prompt (see: Customizing PowerShell Prompt - Equivalent to CMD's $M$P$_$+$G?)

like image 230
JJarava Avatar asked Oct 01 '08 16:10

JJarava


People also ask

How do I list a network drive in PowerShell?

We can query network drives using PowerShell with the Get-WmiObject cmdlet. You can query the Win32_MappedLogicalDisk WMI class which represents network storage devices that are mapped as logical disks on the computer system. Note: You can query a remote computer with the $computer variable.

How do I find network drive details?

To check the path of a network drive using File Explorer, click on 'This PC' on the left panel in Explorer. Then double-click the mapped drive under 'Network Locations'. The path of the mapped network drive can be seen at the top.


1 Answers

Use the .NET framework:

PS H:\> $x = new-object system.io.driveinfo("h:\")
PS H:\> $x.drivetype
Network
like image 55
Jeff Stong Avatar answered Nov 09 '22 20:11

Jeff Stong