Functions/Check-ServiceNotExistsError.ps1

<#
    .SYNOPSIS
    Gives error message if a service does not exists.
    .DESCRIPTION
    Gives error message if a service does not exists.
    .EXAMPLE
    Check-ServiceNotExistsError -ServerInstance 'DynamicsNav100'
    .PARAMETER ServerInstance
    Name of the nav Server Instance to check corresponding service
#>


function Check-ServiceNotExistsError
{
    param
    (
        [parameter(Mandatory=$true,Position=0)]
        [string] $ServerInstance
    )
    PROCESS
    {
        $ServiceFound = (Get-Service -name "*$ServerInstance") 
        IF([string]::IsNullOrEmpty($ServiceFound))
        {
            Write-Error ("Service does not exist for serverinstance: $ServerInstance ") -ErrorAction Stop
        }
    }
}

Export-ModuleMember -Function Check-ServiceNotExistsError