我正在尝试使用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/