Skip to main content

Manage a Running PowerShell Service

Problem

You want to manage a running service.

Solution

To stop a service, use the StopService cmdlet:

PS >StopService AudioSrv WhatIf What if: Performing operation "StopService" on Target "Windows Audio (Audi oSrv)".

Likewise, use the SuspendService, RestartService, and ResumeService cmdlets to suspend, restart, and resume services, respectively.

For other tasks (such as setting the startup mode), use the GetWmiObject cmdlet:

$service = GetWmiObject Win32_Service |

WhereObject { $_.Name eq "AudioSrv" } $service.ChangeStartMode("Manual") $service.ChangeStartMode("Automatic")

Discussion

The StopService cmdlet lets you stop a service either by name or display name.

Notice that the solution uses the –WhatIf flag on the StopService cmdlet. This parameter lets you see what would happen if you were to run the command but doesn’t actually perform the action.

For more information about the StopService cmdlet, type GetHelp StopService.If you want to suspend, restart, or resume a service, see the SuspendService, RestartService, and ResumeService cmdlets, respectively.

If you need dedicated infrastructure for managing running PowerShell services, consider a Singapore Dedicated Server for greater control over service management, system monitoring, PowerShell automation, server administration, and Windows-based application workloads.

Help Category