国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > PowerShell > 正文

Windows Powershell排序和分組管道結(jié)果

2020-05-30 20:15:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

使用Sort-Object和Group-Object可以對(duì)管道結(jié)果進(jìn)行分組。
其實(shí)每條命令執(zhí)行后的結(jié)果已經(jīng)排過(guò)序了。例如通過(guò)ls 查看文件列表,默認(rèn)會(huì)根據(jù)Name屬性進(jìn)行排序,但是你可以通過(guò)指定屬性進(jìn)行排序例如:

PS C:Powershell> ls | Sort-Object LengthMode     LastWriteTime Length Name----     ------------- ------ -----a--- 2011/11/28   15:30   63 ping.bat-a--- 2011/12/2   18:47  140 test.ps1-a--- 2011/11/28   16:42  170 test.vbs-a--- 2011/11/28   11:12  186 LogoTestConfig.xml-a--- 2011/11/23   17:37  242 test.txt-a--- 2011/11/25   11:20  556 employee.xml

這樣默認(rèn)會(huì)根據(jù)length進(jìn)行升序排序,如果要降序排列,可是使用Descending選項(xiàng)。

PS C:Powershell> ls | Sort-Object Length -DescendingMode     LastWriteTime Length Name----     ------------- ------ -----a--- 2011/11/24   17:44 735892 Powershell_Cmdlets.html-a--- 2011/11/24   18:30 67580 a.html-a--- 2011/11/24   20:04 26384 a.txt-a--- 2011/11/29   19:23 21466 function.ps1-a--- 2011/11/24   20:26 12060 alias-a--- 2011/11/24   17:37  7420 name.html

給對(duì)象和哈希表進(jìn)行排序

如果要完成主要關(guān)鍵字降序,次要關(guān)鍵字升序的排序,可能首先想到的是:

PS C:Powershell> Dir | Sort-Object Length, Name -descending, -ascendingSort-Object : 找不到接受實(shí)際參數(shù)“System.Object[]”的位置形式參數(shù)。所在位置 行:1 字符: 18+ Dir | Sort-Object <<<< Length, Name -descending, -ascending  + CategoryInfo     : InvalidArgument: (:) [Sort-Object], ParameterBin  dingException  + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell  .Commands.SortObjectCommand

但是上面的方法行不通,可是這樣操作:

PS C:Powershell> Dir | Sort-Object @{expression="Length";Descending=$true},@{expression="Name";Ascending=$true}  目錄: C:PowershellMode     LastWriteTime Length Name----     ------------- ------ -----a--- 2011/11/24   17:44 735892 Powershell_Cmdlets.html-a--- 2011/11/24   18:30 67580 a.html-a--- 2011/11/24   20:04 26384 a.txt-a--- 2011/11/29   19:23 21466 function.ps1-a--- 2011/11/24   20:26 12060 alias-a--- 2011/11/24   17:37  7420 name.html-a--- 2011/12/14   11:22  3460 ls.html-a--- 2011/11/30   16:04  2556 psdrive.html-a--- 2011/11/25   11:20  556 employee.xml-a--- 2011/11/23   17:37  242 test.txt-a--- 2011/11/28   11:12  186 LogoTestConfig.xml-a--- 2011/11/28   16:42  170 test.vbs-a--- 2011/12/2   18:47  140 test.ps1

對(duì)數(shù)據(jù)進(jìn)行分組

如果想查看當(dāng)前關(guān)閉和開(kāi)啟的所有服務(wù),并且通過(guò)狀態(tài)進(jìn)行分組。可是使用:

PS C:Powershell> Get-Service | Group-Object StatusCount Name  Group----- ----  -----  87 Running {System.ServiceProcess.ServiceController, System.ServiceProcess.S       erviceController, System.ServiceProcess.ServiceController, System       .ServiceProcess.ServiceController...}  88 Stopped {System.ServiceProcess.ServiceController, System.ServiceProcess.S       erviceController, System.ServiceProcess.ServiceController, System       .ServiceProcess.ServiceController...}            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 靖宇县| 乌拉特后旗| 长寿区| 申扎县| 土默特右旗| 安仁县| 舟曲县| 囊谦县| 皮山县| 宜兴市| 伊川县| 买车| 灵石县| 三江| 栾川县| 勐海县| 手游| 迁西县| 隆德县| 彩票| 历史| 外汇| 扶余县| 岐山县| 平泉县| 澄迈县| 西平县| 金川县| 衡南县| 肥城市| 乌拉特中旗| 措勤县| 武夷山市| 辽阳县| 南木林县| 巫溪县| 鄢陵县| 马山县| 宁化县| 普兰店市| 石景山区|