Question:
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”:
1 2 3 4 5 6 7 |
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:
1 2 3 4 5 6 7 8 |
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?)
Answer:
Use the .NET framework:
1 2 3 4 |
PS H:\> $x = new-object system.io.driveinfo("h:\") PS H:\> $x.drivetype Network |