﻿[CmdletBinding()]

Param
(
    # Param1 help description
    [Parameter(Mandatory=$true,
               ValueFromPipelineByPropertyName=$true,
               Position=0)]
    [String]
    $ServiceName
)

$service = Get-Service $ServiceName -ErrorAction SilentlyContinue

if ($service)
{
    $service.Stop()
}
    
﻿[CmdletBinding()]

Param
(
    # Param1 help description
    [Parameter(Mandatory=$true,
               ValueFromPipelineByPropertyName=$true,
               Position=0)]
    [String]
    $ServiceName
)

$service = Get-Service $ServiceName -ErrorAction SilentlyContinue

if ($servicem -and $service.CanStop)
{
    $service.Stop()
}
    
Check service status. You can't stop "stoped service".
Check service status.  You can't stop "stoped service".
