簡體   English   中英

列出 Powershell 中的所有設備、分區和卷

[英]List all devices, partitions and volumes in Powershell

我有多個卷(現在幾乎每個人都有):在 Windows 上,它們最終指定為 C:、D: 等等。 如何在 Unix 機器上使用“ls /mnt/”和 Powershell 列出所有這些?

要獲取所有文件系統驅動器,您可以使用以下命令:

gdr -PSProvider 'FileSystem'

gdrGet-PSDrive的別名,它包括注冊表等的所有“虛擬驅動器”。

Get-Volume

您將獲得:DriveLetter、FileSystemLabel、FileSystem、DriveType、HealthStatus、SizeRemaining 和 Size。

在 Windows PowerShell 上:

Get-PSDrive 
[System.IO.DriveInfo]::getdrives()
wmic diskdrive
wmic volume

還有實用程序 dskwipe: http ://smithii.com/dskwipe

dskwipe.exe -l

首先,在 Unix 上你使用mount ,而不是ls /mnt :很多東西都沒有安裝在/mnt

無論如何,有mountvol DOS 命令,它繼續在 Powershell 中工作,還有特定於 Powershell 的Get-PSDrive

這已經很老了,但我發現以下值得注意:

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

沒有過濾屬性,在我的測試系統上,4319.4196ms 到 1777.7237ms。 除非我需要返回一個 PS-Drive 對象,否則我會堅持使用 WMI。

編輯:我認為我們有一個贏家:PS N:> (measure-command {[System.IO.DriveInfo]::getdrives()|%{$_.name}|out-host}).to‌ talmilliseconds 110.9819

雖然這不是“powershell”特定的......您可以使用diskpart輕松列出驅動器和分區,列出卷

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

運行命令:

Get-PsDrive -PsProvider FileSystem

有關更多信息,請參閱:

每個驅動器有多個卷(有些安裝在驅動器的子目錄中)。 此代碼顯示安裝點和卷標的列表。 顯然,您還可以提取可用空間等:

gwmi win32_volume|where-object {$_.filesystem -match "ntfs"}|sort {$_.name} |foreach-object {
  echo "$(echo $_.name) [$(echo $_.label)]"
}

您也可以在 CLI 上使用

net use

您也可以使用以下內容來查找驅動器上的“總”磁盤大小。

Get-CimInstance -ComputerName yourhostname win32_logicaldisk | foreach-object {write " $($ .caption) $('{0:N2}' -f ($ .Size/1gb)) GB 總計,$('{0:N2}' -f ($_.FreeSpace) /1gb)) GB 免費"}

Microsoft 有一種方法可以將其作為其az vm repair腳本的一部分(請參閱: 使用 Azure 虛擬機修復命令修復 Windows VM )。

它在 MIT 許可下可用: https : //github.com/Azure/repair-script-library/blob/51e60cf70bba38316394089cee8e24a9b1f22e5f/src/windows/common/helpers/Get-Disk-Partitions.ps1

如果設備存在,但(尚未)安裝,這有助於:

Get-PnpDevice -PresentOnly -InstanceId SCSI*

替代文字

PS功能:> get-psdrive

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM