使用Windows Powershell从命令行获取服务服务管理

Windows Powershell provides easy to use commands or command-lets to manage Windows systems. Powershell can be used to manage Windows Services and provides builtin command for related operations.

Windows Powershell提供了易于使用的命令或命令集来管理Windows系统。 Powershell可用于管理Windows服务,并提供用于相关操作的内置命令。

帮帮我 (Help)

Help information about Powershell Services command can be get wit the following command.

可以通过以下命令获取有关Powershell Services命令的帮助信息。

$ Get-Help Get-Service
Get-Service Help
Get-Service Help
获取服务帮助

使用Get-Service列出服务(List Services with Get-Service)

Existing Windows services can be listed with the Powershell command Get-Service . This will list all services currently running, stopped, suspended.

可以使用Powershell命令Get-Service列出现有的Windows Get-Service 。 这将列出当前正在运行,停止,暂停的所有服务。

$ Get-Service
List Services with Get-Service
List Services with Get-Service
使用Get-Service列出服务

While listing services information about the service state, service name and service display name will be provided in separate columns.

在列出有关服务状态的服务信息时,将在单独的列中提供服务名称和服务显示名称。

仅列出正在运行的服务 (Only List Running Services)

In previous example we simply listed services but we may need to list only running services. In order to filter running services we will use Linux grep equivalent Where-Object like below.

在前面的示例中,我们仅列出了服务,但是我们可能仅需要列出正在运行的服务。 为了过滤正在运行的服务,我们将使用Linux grep等效的Where-Object如下所示。

$ Get-Service | Where-Object {$_.status -eq "running"}
Only List Running Services
Only List Running Services
仅列出正在运行的服务

启动服务(Start Service)

One of the most used practice of service command is starting the service. Syntax of starting service command is the same we just change the Verb part of the service command and use Start-Service by providing the service name. In this example we will start the service named RasAuto .

服务命令最常用的一种做法是启动服务。 启动服务命令的语法相同,我们只是更改了服务命令的动词部分,并通过提供服务名称来使用Start-Service。 在此示例中,我们将启动名为RasAuto的服务。

$  Start-Service RasAuto

停止服务 (Stop Service)

Stopping a service is similar to starting we just change start to stop like below. In the example we will stop service named RasAuto

停止服务类似于启动,我们只是将启动更改为停止,如下所示。 在示例中,我们将停止名为RasAuto服务

$  Stop-Service RasAuto

重新启动服务 (Restart Service)

Restarting service is easy as starting and stopping service we will just use Restart-Service command with the service name. Restart will stop and start service if it is working. If it is not working service will just started.

重新启动服务很容易,因为启动和停止服务我们将只使用带有服务名称的Restart-Service命令。 如果重新启动,它将停止并启动服务。 如果它不工作,则服务将刚刚启动。

$ Restart-Service RasAuto

暂停服务 (Suspend Service)

In Windows services can be suspended. It is similar to stopping the service but there are some differences. Suspended service will hold current situations and related data and variables. Also the service stop triggers will not run. In this example we will suspend service named MyService .

在Windows中,可以暂停服务。 它类似于停止服务,但有一些区别。 暂停服务将保存当前情况以及相关数据和变量。 而且,服务停止触发器将不会运行。 在此示例中,我们将暂停名为MyService的服务 

$ Suspend-Service MyService

In order to suspend a service the service should support suspension. If the service do not support suspension and we try to suspend the service we will get an error like below.

为了暂停服务,服务应支持暂停。 如果该服务不支持暂停,而我们尝试暂停该服务,则会收到如下错误。

LEARN MORE  How To Install,Start, Stop, Restart OpenSSH In Ubuntu, Debian, Kali, Mint?
了解更多如何在Ubuntu,Debian,Kali,Mint中安装,启动,停止,重新启动OpenSSH?
Suspend Service
Suspend Service
暂停服务

简历服务(Resume Service)

Suspended service can be resumed with the Resume-Service command like below.

可以使用如下的Resume-Service命令来恢复暂停的服务。

$ Resume-Service MyService
 

翻译自: https://www.poftut.com/get-service-service-management-with-windows-powershell-from-command-line/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值