In PowerShell, come posso determinare la radice di un'unità (supponendo che sia un'unità di rete)

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

Domanda

In PowerShell, anche se è possibile sapere se un'unità è un'unità di rete: vedere In PowerShell, come posso determinare se l'unità corrente è un'unità di rete oppure no?

Quando provo a ottenere il " root " dell'unità, ricevo la lettera dell'unità.

L'impostazione: MS-Dos "uso netto" mostra che H: è davvero un'unità di rete mappata:

New connections will be remembered.

Status       Local     Remote                    Network
-------------------------------------------------------------------------------
OK           H:        \\spma1fp1\JARAVJ$        Microsoft Windows Network

The command completed successfully.

Get-PSDrive ci dice che il root è H:

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

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

e l'utilizzo di system.io.driveinfo non ci fornisce una risposta completa:

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:\

Qualche idea su come ottenere tali informazioni?

Grazie

È stato utile?

Soluzione

Prova WMI:

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

Altri suggerimenti

Il trucco è che il nome dell'attributo è diverso da quello previsto. Prova:

(Get-PSDrive h) .DisplayRoot

$ drive = gwmi win32_logicaldisk -filter " DeviceID = 'H:' " if ($ drive.DriveType -eq 4) {write-host " drive è una condivisione di rete "}

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top