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

主頁 > 知識庫 > Windows Powershell ForEach-Object 循環

Windows Powershell ForEach-Object 循環

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

對管道對象逐個處理

如果使用Get-WmiObject 獲取系統中的服務,為了排版可能會也會使用Format-Table對結果進行表格排版。

復制代碼 代碼如下:

PS C:Powershell> Get-WmiObject Win32_Service | Format-Table status,DisplayName
-AutoSize

status DisplayName
------ -----------
OK     Adobe Acrobat Update Service
OK     Application Experience
OK     Application Layer Gateway Service
OK     Application Host Helper Service
OK     Application Identity
OK     Application Information
OK     Application Management
OK     ASP.NET State Service

但是如果想對每個服務進行更定制化的處理可是使用ForEach-Object

復制代碼 代碼如下:

PS C:Powershell> Get-WmiObject Win32_Service | ForEach-Object {"Name:"+ $_.Disp
layName, ", Is ProcessId more than 100:" + ($_.ProcessId -gt 100)}
Name:Adobe Acrobat Update Service , Is ProcessId more than 100:True
Name:Application Experience , Is ProcessId more than 100:False
Name:Application Layer Gateway Service , Is ProcessId more than 100:False
Name:Application Host Helper Service , Is ProcessId more than 100:True
Name:Application Identity , Is ProcessId more than 100:True
Name:Application Information , Is ProcessId more than 100:True
Name:Application Management , Is ProcessId more than 100:False
Name:ASP.NET State Service , Is ProcessId more than 100:False

結合條件處理

ForEach-Object的處理可以包含任意Powershell腳本,當然也包括條件語句

復制代碼 代碼如下:

Get-WmiObject Win32_Service | ForEach-Object {
    if ($_.ProcessId -gt 3000)
    { "{0}({1})" -f $_.DisplayName,$_.ProcessID}
}
Windows Presentation Foundation Font Cache 3.0.0.0(5408)
Microsoft Network Inspection(5260)
BranchCache(4112)
Windows Modules Installer(7656)

調用方法

在ForEach-Object中,$_代表當前對象,當然也允許通過$_,調用該對象支持的方法。
下面的例子殺死所有IE瀏覽器進程:

復制代碼 代碼如下:

PS C:Powershell> Get-Process iexplore

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
    883      29    14728      22432   181    34.26   4300 iexplore
    771      28    55552     129152   425     8.56   5732 iexplore
   1216      51   104324     143916   539   572.41   5912 iexplore
    801      25    49200      25372   285     5.99   6252 iexplore
    691      25    57564      95796   333     8.08   6388 iexplore
   1256      38    85848     127012   379    20.37   7856 iexplore

PS C:Powershell> Get-Process iexplore | ForEach-Object {$_.kill()}
PS C:Powershell> Get-Process iexplore
Get-Process : 找不到名為“iexplore”的進程。請驗證該進程名稱,然后再次調用 cmdlet。
所在位置 行:1 字符: 12
+ Get-Process iexplore
+ CategoryInfo : ObjectNotFound: (iexplore:String) [Get-Process],
ProcessCommandException
+ FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.
Commands.GetProcessCommand

您可能感興趣的文章:
  • Windows Powershell IF-ELSEIF-ELSE 語句
  • Windows Powershell Switch 語句
  • Windows Powershell Foreach 循環
  • Windows Powershell Do While 循環
  • Windows Powershell For 循環
  • Windows Powershell Switch 循環

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

巨人網絡通訊聲明:本文標題《Windows Powershell ForEach-Object 循環》,本文關鍵詞  Windows,Powershell,ForEach-Object,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Windows Powershell ForEach-Object 循環》相關的同類信息!
  • 本頁收集關于Windows Powershell ForEach-Object 循環的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 望城县| 水城县| 红原县| 广宗县| 页游| 方城县| 济宁市| 梁平县| 景德镇市| 五大连池市| 靖江市| 西畴县| 博湖县| 宁远县| 卫辉市| 乌拉特前旗| 巴里| 丰顺县| 潮州市| 台州市| 揭东县| 疏附县| 榆林市| 磴口县| 安达市| 宁武县| 抚州市| 凤山市| 龙里县| 安阳市| 闸北区| 白银市| 泽普县| 汾西县| 南靖县| 花垣县| 耒阳市| 城固县| 邻水| 古蔺县| 衡阳市|