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

作者:神秘网友 发布时间:2020-10-15 21:17:47

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

使用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
使用Windows Powershell从命令行获取服务服务管理
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
使用Windows Powershell从命令行获取服务服务管理
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"}
使用Windows Powershell从命令行获取服务服务管理
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?
使用Windows Powershell从命令行获取服务服务管理
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/

使用Windows Powershell从命令行获取服务服务管理相关教程

  1. 使用Systeminfo显示适用于Windows操作系统的详细系统信息

    使用Systeminfo显示适用于Windows操作系统的详细系统信息 Windows operating system have a lot of third party tools used to get detailed system information like operating system, version, boot time, processor etc. We will look simple single comm

  2. windows命令行快捷键_Windows配置工具命令行快捷方式

    windows命令行快捷键_Windows配置工具命令行快捷方式 windows命令行快捷键 Windows have a lot of tools to manage the operating system and user related configuration. As windows mainly used through GUI accessing some tools needs a lot of navigati

  3. 如何以Windows的不同方式从命令行启动应用程序?

    如何以Windows的不同方式从命令行启动应用程序? Windows is very user friendly and GUI oriented operating system. Other operating systems like Unix, Linux, BSD came from non-GUI heritance and adopted the GUI experience in recent decade very go

  4. 如何使用Dir在Windows命令行中导航,列出文件和目录?

    如何使用Dir在Windows命令行中导航,列出文件和目录? Windows operating system provides command line tool named MS-DOS. This command line have different tools and capabilities for daily operations. We will look some simple steps about usage li

  5. 企业级用户画像:基于USG模型使用决策树开发用户购物性别

    企业级用户画像:基于USG模型使用决策树开发用户购物性别 絮叨两句: 博主是一名数据分析实习生,利用博客记录自己所学的知识,也希望能帮助到正在学习的同学们 人的一生中会遇到各种各样的困难和折磨,逃避是解决不了问题的,唯有以乐观的精神去迎接生活的挑战

  6. Windows中带有MS-DOS命令提示符的循环

    Windows中带有MS-DOS命令提示符的循环 Windows operating system provides MS-DOS from easily days of its creation. MS-DOS is a platform generally used as a command line.MD-DOS have a lot of features those provides programming capabilities. In t

  7. 如何在Windows中使用Schtasks从命令行计划任务?

    如何在Windows中使用Schtasks从命令行计划任务? Recurring tasks are generally schedules with scheduled task manager. Scheduled task manager have GUI for management but creating a task in 20 different servers is very hard and trivial job. Wind

  8. 如何在Windows中使用Xcopy复制文件和备份?

    如何在Windows中使用Xcopy复制文件和备份? Windows provides very featureful command which is used to copy files can take backups named xcopy . Xcopy can be used copy files from one partition to other partition or a usb drive. Xcopy also suppo