powershell - 在Powershell中按可用空间对驱动器进行排序

标签 powershell

我正在尝试使用Powershell按可用空间对驱动器进行排序。该实用程序的目的是在几乎不满的所有磁盘上重新分配几乎已满的一个磁盘。

当前,我的powershell脚本如下所示:

# Retrieves drives from My Computer
$Drives = gdr -PSProvider FileSystem

# Iterates over all drives found
foreach($Drive in $Drives) {
    $Drive | Sort-Object -Property Free
}

输出是这样的:
Name           Used (GB)     Free (GB) Provider      Root                                                                           CurrentLocation
----           ---------     --------- --------      ----                                                                           ---------------
C                 151.09        688.31 FileSystem    C:\                                                                              
D                   0.05         15.67 FileSystem    D:\                                                                                           
F                   0.09          2.96 FileSystem    F:\                                                                                           
G                   0.05         16.43 FileSystem    G:\                                                                                           
H                   0.03          9.73 FileSystem    H:\                                                                                           
I                   2.42         65.94 FileSystem    I:\       

但是我希望像Free(GB)列这样的内容按ASC排序

有什么线索吗?

最佳答案

问题是我排序单个驱动器而不是@johnrsharpe和@Lee_Dailey指出的集合

最终解决了我的问题:

# Iterates over all drives found
$SortedDrives = $Drives | Sort-Object -Property Used -Descending

foreach ($Drive in $SortedDrives) {
    Write-Output $Drive.Name
}

关于powershell - 在Powershell中按可用空间对驱动器进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59865945/

相关文章:

powershell - GetDate 为负 30 分钟并以 UTC 格式显示

Powershell 安装 - 未找到指定搜索条件和模块名称的匹配项

powershell - 停止关闭$ Host.UI.PromptForChoice窗口

powershell - 尝试将 JSON 反序列化为 Powershell 中的类型化对象

Powershell Windows 2003 通配符不起作用

powershell - 如何读取文件夹中的每个csv文件并从csv文件中删除引号字符?

powershell - 将 powershell 输出和错误重定向到控制台(实时)和变量

Powershell 在执行 exe 时关闭

powershell - PowerShell获取文件名,文件夹中没有路径和TSV行数

powershell - TFS:在服务器重新启动或 Windows 更新安装时触发构建的最佳方式