Share via

Remove all service starting with a using powershell

srinath sarman 41 Reputation points
2020-10-18T09:13:22.887+00:00

Hello,

I am looking for command to delete service starting with "a" or "azure" using powershell 4

Thanks,
Srinath.

Windows for business | Windows Server | User experience | PowerShell

3 answers

Sort by: Most helpful
  1. Rich Matheisen 48,116 Reputation points
    2020-10-18T14:40:14.587+00:00

    There may be quite a few services whose name begins with the letter "a"! I don't think I'd use that as a criterion.

    I'd start by running this:

    Get-Service "azure*" |
        ForEach-Object{
            Stop-Service $_ -WhatIf:$true
            Get-CimInstance -ClassName Win32_Service -Filter "Name='$_'" | 
                Remove-CimInstance -WhatIf:$true
        }
    

    Check the output carefully to be sure that you haven't inadvertently included some necessary service. When you're sure the results aren't going to disrupt your operation, remove the "-WhatIf:$true" switches from the Stop-Service and Remove-CimInstance cmdlets.

    2 people found this answer helpful.
    0 comments No comments

  2. Anonymous
    2020-10-19T06:03:11.223+00:00

    Hi,
    sc.exe can delete a service for you
    https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/sc-delete

    You could call it in powershell like this

    Get-Service "azure*" | ForEach-Object{$ServiceName=$_.name; Invoke-Expression "sc.exe delete $ServiceName"}  
    

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. T. Kujala 8,806 Reputation points
    2020-10-18T11:45:05.167+00:00

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.