赞
踩
Service are one of the most important part of the operating systems. There are different tools and commands to list these services. Powershell provides Get-Service
commandlet in order to list these services and filter them acording to the provided filter.
服务是操作系统中最重要的部分之一。 有不同的工具和命令来列出这些服务。 Powershell提供了Get-Service
命令集,以便列出这些服务并根据提供的过滤器对其进行过滤。
We will start with a simple use case where we will list all services without providing an options to the Get-Service
command. This will list currently existing service with running or stopped status.
我们将从一个简单的用例开始,在该用例中,我们将列出所有服务,而不为Get-Service
命令提供选项。 这将列出处于运行或停止状态的当前现有服务。
PS> Get-Service
As we can see from screenshot services are ordered by name by default. Following information is provided by default about listed services.
从屏幕截图中可以看出,默认情况下,服务按名称排序。 默认情况下,提供以下有关所列服务的信息。
Status
will display if the service is Running
or Stopped
如果服务正在Running
或已Stopped
将显示Status
Name
will display the real and short name of the service which is used by commands.
Name
将显示命令使用的服务的真实名称和简称。
Display Name
will show extended and informative name of the service which is more human friendly.
Display Name
将显示服务的扩展Display Name
和信息性名称,更人性化。
As Microsoft provided remote access and management of the remote systems with powreshell we can use Get-Service
command in order to list services on the remote systems. We will provide the -computername
of the remote system. This can a DNS name which can be resolved or a IP address we can access.
由于Microsoft通过powreshell提供了对远程系统的远程访问和管理,因此我们可以使用Get-Service
命令来列出远程系统上的服务。 我们将提供远程系统的-computername
。 这可以是可以解析的DNS名称,也可以是我们可以访问的IP地址。
PS > Get-Service -computername DESKTOP-HQVAMA3
Windows operating systems has a lot of services which will fill the terminal easily. Or we may need to list specific service name by providing its name of some part of its name. We will just provide the name after Get-Service
command. We can also use *
glob where only some part of the service name will be specified. In this example we will try to list WinDefend
service by providing WinDef*
as service name.
Windows操作系统有很多服务,可以很容易地填充终端。 或者,我们可能需要通过提供其名称中某些部分的名称来列出特定的服务名称。 我们将仅在Get-Service
命令后提供名称。 我们也可以使用*
glob,其中仅指定服务名称的一部分。 在此示例中,我们将尝试通过提供WinDef*
作为服务名称来列出WinDefend
服务。
PS > Get-Service WinDef*
There is two main service status in Windows. Running
or Stopped
. We may need to list services according to their status. We can use object parameter Status
like below which will list only running services.
Windows中有两种主要服务状态。 Running
或已Stopped
。 我们可能需要根据服务状态列出服务。 我们可以使用如下所示的对象参数Status
,它将仅列出正在运行的服务。
PS> Get-Service | Where-Object {$_.Status -eq "Running"}
Services are important and may be linked and dependent to each other. Before stopping them we may need to list dependent services of the given service. We can use -RequiredServices
options in order to list service dependencies.
服务很重要,可以相互链接并相互依赖。 在停止它们之前,我们可能需要列出给定服务的依赖服务。 我们可以使用-RequiredServices
选项以列出服务依赖性。
PS> Get-Service "WinDefend" -RequiredServices
We may need to check service list according to their Running and Stopped status. We can sort them by usingSort-Object
like below.
我们可能需要根据服务的“正在运行”和“已停止”状态检查服务列表。 我们可以使用如下所示的Sort-Object
对它们进行Sort-Object
。
PS> Get-Service | Sort-Object status
We may need to investigate service list later or we just want to save them in to a file. We can use Out-File
command which will write the service list the file we want. In this example we will write into a file named Services.txt
我们可能稍后需要调查服务列表,或者我们只想将它们保存到文件中。 我们可以使用Out-File
命令将服务列表写入所需的文件。 在此示例中,我们将写入名为Services.txt
的文件
PS> Get-Service | Out-File "C:\Users\İsmail Baydan\Desktop\Services.txt"
翻译自: https://www.poftut.com/how-to-check-windows-service-status-with-get-service-command-in-powershell/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。