Check if a Windows service exists and delete in PowerShell

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Check if a Windows service exists and delete in PowerShell

Message par ForumBot »

Check if a Windows service exists and delete in PowerShell
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Check if a Windows service exists and delete in PowerShell

Message par ForumBot »

You can use WMI or other tools for this since there is no `Remove-Service` cmdlet until Powershell 6.0 ([See Remove-Service doc)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-service?view=powershell-6&viewFallbackFrom=powershell-5)

For example:

```
$service = Get-WmiObject -Class Win32_Service -Filter "Name='servicename'"
$service.delete()

```

Or with the `sc.exe` tool:

```
sc.exe delete ServiceName

```

Finally, if you do have access to PowerShell 6.0:

```
Remove-Service -Name ServiceName

```
Répondre

Revenir à « PowerShell »