对管道对象逐个处理
如果使用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
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 泰迪罗宾.1984-天外人(2004环球复黑王)【宝丽金】【WAV+CUE】
- 《网络夜色风 2CD》[WAV/分轨][1GB]
- 《发烧金曲金装影视 绝对超值不容错过 2CD》[WAV/分轨][600MB]
- 《林俊杰 最具影响力的创作歌手 JJ林俊杰 2CD》[WAV+CUE][940MB]
- 《CATO 黄油猫》评测:和物理老师说再见……吗?
- 《Ara:不为人知的历史》:抗衡《文明》?4X游戏挑战者
- 《艾诺提亚:失落之歌》:令人失望的意大利特色试验品
- 《蛋仔派对》斯派克皮肤图鉴
- 黑神话悟空九种美酒在哪获得 黑神话悟空九种酒位置一览
- 黑神话悟空全丹药配怎么获取 黑神话悟空全丹药配方获取方式介绍
- 梁汉文2014-听后感[天凯唱片][WAV+CUE]
- 徐小明1984-剑胆琴心(LP版)[文志][WAV+CUE]
- 韩红-精选(庆功版)[WAV整轨]
- 《暗喻幻想:ReFantazio》获IGN法国满分评价:完美的新标杆之作
- 《暗喻幻想》开分后 开发者小姐姐感动到热泪盈眶