PowerShell에서는 드라이브의 루트를 어떻게 결정할 수 있습니까 (네트워크 드라이브라고 가정)

StackOverflow https://stackoverflow.com/questions/158520

문제

PowerShell에서 드라이브가 네트워크 드라이브인지 알 수 있더라도 : PowerShell에서는 현재 드라이브가 네트워크 드라이브인지 아닌지를 어떻게 결정할 수 있습니까?

드라이브의 "루트"를 얻으려고 할 때 드라이브 편지를 되 찾습니다.

설정 : MS-DOS "NET 사용"은 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:\

그 정보를 얻는 방법에 대한 아이디어가 있습니까?

감사

도움이 되었습니까?

해결책

WMI를 시도해보십시오 :

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

다른 팁

속성은 속성 이름이 예상과 다르다는 것입니다. 노력하다:

(Get-PSDrive h).DisplayRoot

$ drive = gwmi win32_logicaldisk -filter "deviceId = 'h :'"if ($ drive.drivetype -eq 4) {쓰기 호스트 "드라이브는 네트워크 공유"}

$ fso = new -Object -com "Scripting.FilesyStemObject"$ fso.getDrive ( "Y"). ShareName

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top