Remove-HTAllServices.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function Remove-HTAllServices {
    [CmdletBinding()]
    param (
        # Switch to confirm all service deletitions.
        [switch]
        $ConfirmAll   
    )
    process
    {
        $services = Get-WmiObject -Class Win32_Service -Filter "Name like 'csm%'"
        foreach($serv in $services)
        {
            if($ConfirmAll)
            {
                Write-Warning "Deleting Service $($serv.Name)"
                $serv.delete()
            }
            else
            {
                $option = Read-Host -Prompt "Remove service $($serv.Name) y/n"
                if($option -eq 'y')
                {
                    $serv.delete()
                } 
            }
        }
    }

}