列出Powershell中的所有设备,分区和卷

时间:2021-12-19 20:49:56

I have multiple volumes (as nearly everybody nowadays): on Windows they end up specified as C:, D: and so on. How do I list these all like on a Unix machine with "ls /mnt/" with Powershell?

我有多个卷(现在几乎每个人都有):在Windows上,它们最终指定为C:,D:等等。如何在带有Powershell的“ls / mnt /”的Unix机器上列出这些内容?

8 个解决方案

#1


54  

To get all of the file system drives, you can use the following command:

要获取所有文件系统驱动器,可以使用以下命令:

gdr -PSProvider 'FileSystem'

gdr is an alias for Get-PSDrive, which includes all of the "virtual drives" for the registry, etc.

gdr是Get-PSDrive的别名,它包含注册表的所有“虚拟驱动器”等。

#2


9  

Get-Volume

获取批量

you will get: DriveLetter, FileSystemLabel, FileSystem, DriveType, HealthStatus, SizeRemaining and Size

你会得到:DriveLetter,FileSystemLabel,FileSystem,DriveType,HealthStatus,SizeRemaining和Size

#3


7  

On Windows Powershell:

在Windows Powershell上:

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

Also the utility dskwipe: http://smithii.com/dskwipe

实用程序dskwipe:http://smithii.com/dskwipe

dskwipe.exe -l

#4


4  

Firstly, on Unix you use mount, not ls /mnt: many things are not mounted in /mnt.

首先,在Unix上使用mount,而不是ls / mnt:/ mnt中没有安装很多东西。

Anyhow, there's the mountvol DOS command, which continues to work in Powershell, and there's the Powershell-specific Get-PSDrive.

无论如何,还有mountvol DOS命令,它继续在Powershell中运行,并且还有Powershell特定的Get-PSDrive。

#5


2  

This is pretty old, but I found following worth noting:

这是相当古老的,但我发现以下值得注意:

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

Without filtering properties, on my test system, 4319.4196ms to 1777.7237ms. Unless I need a PS-Drive object returned, I'll stick with WMI.

没有过滤属性,在我的测试系统上,4319.4196ms到1777.7237ms。除非我需要返回PS-Drive对象,否则我会坚持使用WMI。

EDIT: I think we have a winner: PS N:> (measure-command {[System.IO.DriveInfo]::getdrives()|%{$_.name}|out-host}).to‌​talmilliseconds 110.9819

编辑:我认为我们有一个胜利者:PS N:>(measure-command {[System.IO.DriveInfo] :: getdrives()|%{$ _。name} | out-host})。to talmilliseconds 110.9819

#6


1  

Though this isn't 'powershell' specific... you can easily list the drives and partitions using diskpart, list volume

虽然这不是'powershell'特定的......你可以使用diskpart,list 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

#7


0  

列出Powershell中的所有设备,分区和卷

PS Function:> get-psdrive

PS功能:> get-psdrive

#8


0  

We have multiple volumes per drive (some are mounted on subdirectories on the drive). This code shows a list of the mount points and volume labels. Obviously you can also extract free space and so on:

我们每个驱动器有多个卷(一些安装在驱动器上的子目录中)。此代码显示装入点和卷标的列表。显然你也可以提取*空间等等:

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

#1


54  

To get all of the file system drives, you can use the following command:

要获取所有文件系统驱动器,可以使用以下命令:

gdr -PSProvider 'FileSystem'

gdr is an alias for Get-PSDrive, which includes all of the "virtual drives" for the registry, etc.

gdr是Get-PSDrive的别名,它包含注册表的所有“虚拟驱动器”等。

#2


9  

Get-Volume

获取批量

you will get: DriveLetter, FileSystemLabel, FileSystem, DriveType, HealthStatus, SizeRemaining and Size

你会得到:DriveLetter,FileSystemLabel,FileSystem,DriveType,HealthStatus,SizeRemaining和Size

#3


7  

On Windows Powershell:

在Windows Powershell上:

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

Also the utility dskwipe: http://smithii.com/dskwipe

实用程序dskwipe:http://smithii.com/dskwipe

dskwipe.exe -l

#4


4  

Firstly, on Unix you use mount, not ls /mnt: many things are not mounted in /mnt.

首先,在Unix上使用mount,而不是ls / mnt:/ mnt中没有安装很多东西。

Anyhow, there's the mountvol DOS command, which continues to work in Powershell, and there's the Powershell-specific Get-PSDrive.

无论如何,还有mountvol DOS命令,它继续在Powershell中运行,并且还有Powershell特定的Get-PSDrive。

#5


2  

This is pretty old, but I found following worth noting:

这是相当古老的,但我发现以下值得注意:

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

Without filtering properties, on my test system, 4319.4196ms to 1777.7237ms. Unless I need a PS-Drive object returned, I'll stick with WMI.

没有过滤属性,在我的测试系统上,4319.4196ms到1777.7237ms。除非我需要返回PS-Drive对象,否则我会坚持使用WMI。

EDIT: I think we have a winner: PS N:> (measure-command {[System.IO.DriveInfo]::getdrives()|%{$_.name}|out-host}).to‌​talmilliseconds 110.9819

编辑:我认为我们有一个胜利者:PS N:>(measure-command {[System.IO.DriveInfo] :: getdrives()|%{$ _。name} | out-host})。to talmilliseconds 110.9819

#6


1  

Though this isn't 'powershell' specific... you can easily list the drives and partitions using diskpart, list volume

虽然这不是'powershell'特定的......你可以使用diskpart,list 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

#7


0  

列出Powershell中的所有设备,分区和卷

PS Function:> get-psdrive

PS功能:> get-psdrive

#8


0  

We have multiple volumes per drive (some are mounted on subdirectories on the drive). This code shows a list of the mount points and volume labels. Obviously you can also extract free space and so on:

我们每个驱动器有多个卷(一些安装在驱动器上的子目录中)。此代码显示装入点和卷标的列表。显然你也可以提取*空间等等:

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