Ho più volumi (come quasi tutti al giorno d'oggi): su Windows vengono specificati come C :, D: e così via. Come li elenco tutti su una macchina Unix con "ls/mnt /" con Powershell?Elenco di tutti i dispositivi, partizioni e volumi in PowerShell
risposta
Per ottenere tutte le unità del file system, è possibile utilizzare il seguente comando:
gdr -PSProvider 'FileSystem'
gdr
è un alias per Get-PSDrive
, che comprende tutte le "unità virtuali" per il Registro di sistema, ecc
maledetto eri più veloce di me :-) – streetparade
Nota che questo potrebbe essere abbreviato in "Get-PSDrive -PSProvider" FileSystem''. Trovo che '| Where-Object' è estremamente lento in molti casi. –
@BaconBits Ho aggiornato la mia risposta per riflettere la migliore opzione. Per i posteri, originariamente avevo 'gdr | dove {$ _. Provider.Name -eq "FileSystem"} ' – bdukes
In primo luogo, su Unix si utilizza mount
, non ls /mnt
: molte cose non sono montate in /mnt
.
In ogni caso, c'è il comando DOS mountvol
, che continua a funzionare in PowerShell, e c'è il Get-PSDrive
specifico di PowerShell.
PS Funzione:>get-PSDrive
Questa è una configurazione elegante per il prompt. Ti dispiacerebbe condividere i dettagli di questo? – wishi
In Windows PowerShell:
Get-PSDrive
[System.IO.DriveInfo]::getdrives()
wmic diskdrive
wmic volume
Anche il dskwipe utility: http://smithii.com/dskwipe
dskwipe.exe -l
Per taggare su, è anche possibile includere un flag da un'altra risposta '-PSProvider: 'FileSystem'' per visualizzare solo i file system. – Pred
Questo è pr Etty vecchio, ma ho trovato seguendo la pena notare:
PS N:\> (measure-command {Get-WmiObject -Class Win32_LogicalDisk|select -property deviceid|%{$_.deviceid}|out-host}).totalmilliseconds
...
928.7403
PS N:\> (measure-command {gdr -psprovider 'filesystem'|%{$_.name}|out-host}).totalmilliseconds
...
169.474
senza filtraggio proprietà, sul mio sistema di test, 4319.4196ms a 1777.7237ms. A meno che non sia necessario un oggetto PS-Drive restituito, rimarrò con WMI.
EDIT: Penso che abbiamo un vincitore: PS N:> (-comando misura {. [System.IO.DriveInfo] :: getdrives() |% {$ _ nome} | Out-Host}) .to talmilliseconds 110,9819
Get-Volume
si otterrà: LetteraUnità, FileSystemLabel, FileSystem, DriveType, HealthStatus, SizeRemaining e dimensione
Get-Volume sembra essere disponibile solo su Windows-Server 2012 e Windows-Server 2016. – Bram
Get-Volume ha funzionato per me con PowerShell 5.1. Forse hanno reso questo standard negli ultimi anni/aggiornamenti recenti. Questa risposta dovrebbe ottenere più attenzione. –
Anche se questo non è 'PowerShell' specifica .. è possibile elencare facilmente unità e partizioni utilizzando diskpart, elenco volume
PS C:\Dev> diskpart
Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: Box
DISKPART> list volume
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 D DVD-ROM 0 B No Media
Volume 1 C = System NTFS Partition 100 MB Healthy System
Volume 2 G C = Box NTFS Partition 244 GB Healthy Boot
Volume 3 H D = Data NTFS Partition 687 GB Healthy
Volume 4 E System Rese NTFS Partition 100 MB Healthy
è possibile ottenere Volume ## usando PowerShell? (Per Windows 7) – Chand
Abbiamo più volumi per unità (alcuni sono montati su sottodirectory sull'unità). Questo codice mostra un elenco dei punti di montaggio e delle etichette del volume. Ovviamente è possibile anche estrarre spazio libero e così via:
gwmi win32_volume|where-object {$_.filesystem -match "ntfs"}|sort {$_.name} |foreach-object {
echo "$(echo $_.name) [$(echo $_.label)]"
}
get-PSDrive tornerà questa Nome Provider Root CurrentLocation ---- -------- ---- ---- ----------- A FileSystem A: Alias Alias C FileSystem C: \ scripts – streetparade