Skip to main content

Test-ServiceExists

SYNOPSISโ€‹

Check to see if a service exists.

SYNTAXโ€‹

Test-ServiceExists [-Name] <String> [[-ComputerName] <String>] [-PassThru] [[-ContinueOnError] <Boolean>]
[<CommonParameters>]

DESCRIPTIONโ€‹

Check to see if a service exists (using WMI method because Get-Service will generate ErrorRecord if service doesn't exist).

EXAMPLESโ€‹

EXAMPLE 1โ€‹

Test-ServiceExists -Name 'wuauserv'

EXAMPLE 2โ€‹

Test-ServiceExists -Name 'testservice' -PassThru | Where-Object { $_ } | ForEach-Object { $_.Delete() }

Check if a service exists and then delete it by using the -PassThru parameter.

PARAMETERSโ€‹

-Nameโ€‹

Specify the name of the service.

Note: Service name can be found by executing "Get-Service | Format-Table -AutoSize -Wrap" or by using the properties screen of a service in services.msc.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ComputerNameโ€‹

Specify the name of the computer. Default is: the local computer.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: $env:ComputerName
Accept pipeline input: False
Accept wildcard characters: False

-PassThruโ€‹

Return the WMI service object. To see all the properties use: Test-ServiceExists -Name 'spooler' -PassThru | Get-Member

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ContinueOnErrorโ€‹

Continue if an error is encountered. Default is: $true.

Type: Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: True
Accept pipeline input: False
Accept wildcard characters: False

CommonParametersโ€‹

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTSโ€‹

Noneโ€‹

You cannot pipe objects to this function.โ€‹

OUTPUTSโ€‹

Noneโ€‹

This function does not return any objects.โ€‹

NOTESโ€‹

https://psappdeploytoolkit.com