What Can I Do With Windows PowerShell?

What Can I Do With Windows PowerShell?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Using the Get-Service Cmdlet

列出服务信息

这也许会让你感到震惊 , 但是 , 真的很简单 :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

gsv

 英文原文:[url]http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/get-service.mspx[/url]

ps:菜菜,英文水平不行,凑合看吧,希望对大家有所帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值