婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Windows Powershell排序和分組管道結果

Windows Powershell排序和分組管道結果

熱門標簽:印臺區呼叫中心外呼系統 六寸地圖標注點怎么刪除 如何根據經緯度百度地圖標注 新鄭電銷機器人一個月多少錢 萬全縣地圖標注app 地圖標注的圖案 莫拉克電梯系統外呼怎么設置 電話機器人公司招聘 騰訊地圖標注中心怎么標注

使用Sort-Object和Group-Object可以對管道結果進行分組。
其實每條命令執行后的結果已經排過序了。例如通過ls 查看文件列表,默認會根據Name屬性進行排序,但是你可以通過指定屬性進行排序例如:

PS C:Powershell> ls | Sort-Object Length
Mode     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

這樣默認會根據length進行升序排序,如果要降序排列,可是使用Descending選項。

PS C:Powershell> ls | Sort-Object Length -Descending
Mode     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

給對象和哈希表進行排序

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

PS C:Powershell> Dir | Sort-Object Length, Name -descending, -ascending
Sort-Object : 找不到接受實際參數“System.Object[]”的位置形式參數。
所在位置 行: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},@{ex
pression="Name";Ascending=$true}

  目錄: C:Powershell

Mode     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

對數據進行分組

如果想查看當前關閉和開啟的所有服務,并且通過狀態進行分組。可是使用:

PS C:Powershell> Get-Service | Group-Object Status
Count 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...}

再舉一例,把當前目錄的文件以擴展名進行分組

PS C:Powershell> ls | Group-Object Extension
Count Name Group
----- ---- -----
  2    {ABC, alias}
  5 .html {a.html, ls.html, name.html, Powershell_Cmdlets.html...}
  2 .txt {a.txt, test.txt}
  2 .xml {employee.xml, LogoTestConfig.xml}
  2 .ps1 {function.ps1, test.ps1}
  1 .bat {ping.bat}
  1 .vbs {test.vbs}

使用表達式分組

如果要查看當前目錄的文件,根據文件的大小是否大于1kb分組。

PS C:Powershell> ls | Group-Object {$_.Length -gt 1kb}

Count Name           Group
----- ----           -----
  7 False           {ABC, employee.xml, LogoTestConfig.xml, ping...
  8 True           {a.html, a.txt, alias, function.ps1...}

如果按照文件名的首字母分組

PS C:Powershell> ls | Group-Object {$_.name.SubString(0,1).toUpper()}
Count Name Group
----- ---- -----
  3 A  {a.html, a.txt, alias}
  1 E  {employee.xml}
  1 F  {function.ps1}
  2 L  {LogoTestConfig.xml, ls.html}
  1 N  {name.html}
  3 P  {ping.bat, Powershell_Cmdlets.html, psdrive.html}
  3 T  {test.ps1, test.txt, test.vbs}

根據當前應用程序的發布者分組

PS C:Powershell> Get-Process | Group-Object Company -NoElement

Count Name
----- ----
  2 Adobe Systems Incorpor...
  52
  2 微軟
  22 Microsoft Corporation
  1 Adobe Systems, Inc.
  1 Microsoft (R) Corporation
  1
  1 NVIDIA Corporation

使用格式化命令分組

Group-Object并不是唯一可以完成分組功能的命令,事實上格式化命令例如Format-Object支持一個GroupBy的參數,也可以完成分組。

PS C:Powershell> Dir | Sort-Object Extension, Name | Format-Table -groupBy Extension

  目錄: C:Powershell

Mode        LastWriteTime   Length Name
----        -------------   ------ ----
-a---    2011/11/24   20:26   12060 alias

  目錄: C:Powershell

Mode        LastWriteTime   Length Name
----        -------------   ------ ----
-a---    2011/11/28   15:30     63 ping.bat

  目錄: C:Powershell

Mode        LastWriteTime   Length Name
----        -------------   ------ ----
-a---    2011/11/24   18:30   67580 a.html
-a---    2011/12/14   11:22    3460 ls.html
-a---    2011/11/24   17:37    7420 name.html
-a---    2011/11/24   17:44   735892 Powershell_Cmdlets.html
-a---    2011/11/30   16:04    2556 psdrive.html

您可能感興趣的文章:
  • PowerShell實現按條件終止管道的方法
  • PowerShell中終止管道的方法
  • PowerShell入門教程之PowerShell管道介紹
  • Windows Powershell導出管道結果
  • Windows Powershell分析和比較管道結果
  • Windows Powershell過濾管道結果
  • Windows Powershell使用管道
  • Windows Powershell 管道和重定向
  • PowerShell函數中接收管道參數實例
  • PowerShell中使用Filter來創建管道輸入函數
  • PowerShell管道入門必看篇(管道例子大全)

標簽:南昌 喀什 天水 汕頭 襄陽 疫苗接種 臨汾 湘潭

巨人網絡通訊聲明:本文標題《Windows Powershell排序和分組管道結果》,本文關鍵詞  Windows,Powershell,排序,和,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Windows Powershell排序和分組管道結果》相關的同類信息!
  • 本頁收集關于Windows Powershell排序和分組管道結果的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 阿拉善盟| 托里县| 司法| 奈曼旗| 定南县| 湘潭市| 黄大仙区| 社旗县| 开远市| 麻城市| 莱阳市| 肥城市| 蓬溪县| 崇仁县| 乐陵市| 若尔盖县| 齐齐哈尔市| 鲁山县| 邓州市| 平阳县| 汝阳县| 福安市| 开化县| 洛阳市| 惠水县| 淳安县| 鄂托克前旗| 保康县| 长寿区| 浪卡子县| 曲阜市| 江源县| 澎湖县| 赣榆县| 乃东县| 谢通门县| 高安市| 石嘴山市| 台湾省| 邵东县| 蒙城县|