> For the complete documentation index, see [llms.txt](https://x7331.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://x7331.gitbook.io/notes/windows-shells/powershell/services.md).

# Services

## Local Services

The `Microsoft.PowerShell.Management` module contains serveral cmdlets for interacting with services.

```powershell
Get-Help *-Service | ft -AutoSize

Name            Category Module                          Synopsis
----            -------- ------                          --------
Resume-Service  Cmdlet   Microsoft.PowerShell.Management Resume-Service...
Restart-Service Cmdlet   Microsoft.PowerShell.Management Restart-Servic...
Set-Service     Cmdlet   Microsoft.PowerShell.Management Set-Service...
Get-Service     Cmdlet   Microsoft.PowerShell.Management Get-Service...
Suspend-Service Cmdlet   Microsoft.PowerShell.Management Suspend-Servic...
Start-Service   Cmdlet   Microsoft.PowerShell.Management Start-Service...
Stop-Service    Cmdlet   Microsoft.PowerShell.Management Stop-Service...
New-Service     Cmdlet   Microsoft.PowerShell.Management New-Service...
```

Services can have a `Status` of: `Running`, `Stopped`, or `Paused` and can be set up to start manually (user interaction), automatically (system startup), or on a delay after system boot.

{% code overflow="wrap" %}

```powershell
# Checking services' status
Get-Service | ft DisplayName,Status

DisplayName                                             Status
-----------                                             ------
Agent Activation Runtime_27727e65                       Stopped
ACC Service                                             Stopped
Adobe Acrobat Update Service                            Stopped
OpenVPN Agent agent_ovpnconnect                         Stopped
AllJoyn Router Service                                  Stopped
Application Layer Gateway Service                       Stopped
Application Identity                                    Stopped
Application Information                                 Running

# Counting the number of services
Get-Service | ft DisplayName,Status -AutoSize | Measure-Object -line

Lines Words Characters Property
----- ----- ---------- --------
  332

# Filtering the services of interest
Get-Service | where DisplayName -like '*Defender*' | ft DisplayName,ServiceName,Status


DisplayName                                             ServiceName  Status
-----------                                             -----------  ------
Windows Defender Firewall                               mpssvc      Running
Microsoft Defender Antivirus Network Inspection Service WdNisSvc    Stopped
Microsoft Defender Antivirus Service                    WinDefend   Running

# Starting a service
Start-Service WdNisSvc
# Stopping a service
Stop-Service WdNisSvc
# Checking the service's statup type
Get-Service WdNisSvc | Select-Object -Property DisplayName,Name,StartType
DisplayName                                             Name     StartType
-----------                                             ----     ---------
Microsoft Defender Antivirus Network Inspection Service WdNisSvc    Manual
# Changing the service's startup type
Set-Service -Name WdNisSvc -StartType Disabled
```

{% endcode %}

## Remote Services

The `-ComputerName` parameter allows us to specify remote hosts.

{% code overflow="wrap" %}

```powershell
# Querying running services on a remote host
Get-Service -ComputerName ACADEMY-ICL-DC | Where-Object {$_.Status -eq "Running"}
# Querying the specified service on multiple hosts
Invoke-Command -ComputerName <hosts> -ScriptBlock {<command>}
Invoke-Command -ComputerName ACADEMY-ICL-DC,LOCALHOST -ScriptBlock {Get-Service -Name 'windefend'}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://x7331.gitbook.io/notes/windows-shells/powershell/services.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
