Skip to content

Instantly share code, notes, and snippets.

Last active November 24, 2021 00:58
What would you like to do?
"puppet_task_version": 1,
"supports_noop": false,
"description": "Stop or restart a service or list of services on a node.",
"parameters": {
"service": {
"description": "The name of the service, or a list of service names to stop.",
"type": "Variant[Array[String],String]"
"norestart": {
"description": "Immediately restart the service(s) after start.",
"type": "Optional[Boolean]"
param (
# Name or list of service names to stop
# Restart the service immediately
foreach ($name in $service) {
$serviceObject = Get-service -Name $name
Write-output "Found Service: $name"
if(-not $serviceObject){
Write-Output "Service not found: $name"
Stop-Service -InputObject $serviceObject -ErrorAction Stop
Write-Output "Stopped service: $name"
Start-Service -InputObject $serviceObject
Write-Output "Started service: $name"
} catch {
Write-Output "Cannot stop service: $name"
Write-Output "Dependent services: $($serviceObject.dependentservices)"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment