Functions/Validations/Test-ServiceNotExistsError.ps1

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


function Test-ServiceNotExistsError
{
    [CmdletBinding()]
    [Alias('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 Test-ServiceNotExistsError -Alias Check-ServiceNotExistsError