按Powershell中的可用空间对驱动器进行排序
我正在尝试使用Powershell按可用空间对驱动器进行排序。此实用程序的目的是将一个几乎已满的磁盘重新分发给所有未满的磁盘 目前,我的powershell脚本如下所示:按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 -Pr
# 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
}
您似乎在列表中对驱动器进行排序,为什么这会改变驱动器的顺序呢?
Free
是该属性的真实名称吗?显示系统通常将道具名称重新映射为“友好名称”。您可以通过管道连接到Get Member
,找到真实姓名另外,正如jornsharpe所指出的,您没有对集合进行排序。尝试将集合直接馈送到排序对象
cmdlet。[grin]@Lee_Dailey yes FREE是属性FREE ScriptProperty系统的真实名称。对象自由{get=##确保这是一个文件系统驱动器…
@ILikeTacos-感谢您的反馈[grin]…请阅读我评论中针对真实问题添加的信息[如jonrsharpe
]。