Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
787 views
in Technique[技术] by (71.8m points)

c# - 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:emp
>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:        \spma1fp1JARAVJ$        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?)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use the .NET framework:

PS H:> $x = new-object system.io.driveinfo("h:")
PS H:> $x.drivetype
Network

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...