What Can I Do With Windows PowerShell?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
列出服务信息
这也许会让你感到震惊
,
但是
,
真的很简单
:Get-Service cmdlet
被设计检索关于在您的计算机安装的服务的信息
. (
某些人认为
PowerShell
太复杂
!)
您想要取得关于在您的计算机安装的所有服务的信息吗
?
我们可以使用
Get-Service
而不用其他另外的参数
:
Get-Service
从这里
,
你将获得这些信息
:
Status Name DisplayName
------ ---- -----------
Running AdobeActiveFile... Adobe Active File Monitor V4
Stopped Alerter Alerter
Running ALG Application Layer Gateway Service
Stopped AppMgmt Application Management
Running ASChannel Local Communication Channel
你将利用
windows powershell
的过滤功能
,
有选择性的获得你在计算机上安装服务的一个集合
.
例如
,
这个命令通过
get-service
和
pipes Where-Object cmdlet.
组合来进行数据的选择
反过来
, Where-Object
可以过滤掉除了被停止的那些服务
:
Get-Service | Where-Object {$_.status –eq "stopped"}
在上面的命令中
, $_.
代表横跨管道通过的对象
.
当状态简单地是服务的属性时我们想要过滤
.
并且,因为我们只感兴趣在被停止的服务
,
我们使用句法
–eq “stopped”.
若我们对正在运行的服务感兴趣
?,
我们可以使用下面的命令
:
Get-Service | Where-Object {$_.status –eq "running"
Status Name DisplayName
------ ---- -----------
Stopped Alerter Alerter
Stopped AppMgmt Application Management
Stopped aspnet_state ASP.NET State Service
Stopped BITS Background Intelligent Transfer Ser...
Stopped Browser Computer Browser
默认情况下
Windows PowerShell
退回以字母顺序被排序的服务
.
我们可以使用
Sort-Object cmdlet,
然而,您能按照排序返回的数据选择所有你所需要的信息
.
例如
,
这个命令首先排序服务由
Status.
然后在
DisplayName:
Get-Service | Sort-Object status,displayname
Get-Service Aliases
| ||
|
英文原文:[url]http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/get-service.mspx[/url]
ps:菜菜,英文水平不行,凑合看吧,希望对大家有所帮助!