1
- Function DeleteServiceWMI {
1
+ Function Remove-WindowsServiceWMI {
2
2
<#
3
3
. SYNOPSIS
4
- Windows service removal script .
5
-
4
+ Removes Windows service using WMI method .
5
+
6
6
. DESCRIPTION
7
- With this funtion you can delete Windows service using WMI method.
8
-
7
+ This function allows you to delete a Windows service using the WMI method.
8
+
9
9
. PARAMETER ServiceName
10
- Mandator - declare name of the service you want to delete.
11
- . PARAMETER ForceIf
12
- NotMandatory - as a precaution measure, default is set to -Whatif . Use this switch to force deletion.
10
+ Mandatory - Declare the name of the service you want to delete.
11
+ . PARAMETER Force
12
+ Not Mandatory - As a precaution measure, the default is set to -WhatIf . Use this switch to force deletion.
13
13
14
14
. EXAMPLE
15
- DeleteServiceWMI -ServiceName W32Time (-ForceIf #-->use to delete)
16
-
15
+ Remove-WindowsServiceWMI -ServiceName W32Time -Force
16
+
17
17
. NOTES
18
- v2
18
+ v0.1.2
19
19
#>
20
20
[CmdletBinding ()]
21
21
param (
22
22
[Parameter (Mandatory = $true )]
23
23
[string ]$ServiceName ,
24
24
25
25
[Parameter (Mandatory = $false )]
26
- [switch ]$ForceIf
26
+ [switch ]$Force
27
27
)
28
28
BEGIN {
29
29
if (! (Get-Service $ServiceName - ErrorAction SilentlyContinue)) {
30
30
Write-Host " Required service not found!" - ForegroundColor Red
31
+ return
31
32
}
32
33
}
33
34
PROCESS {
34
35
$Service = Get-WmiObject - Class Win32_Service - Filter " Name='$ServiceName '"
35
- if (! $ForceIf .IsPresent ) {
36
- Write-Host " Use -ForceIf to actually delete!" - ForegroundColor Cyan
36
+ if (-not $Force .IsPresent ) {
37
+ Write-Host " Use -Force to actually delete!" - ForegroundColor Cyan
37
38
}
38
39
else {
39
40
$Service.StopService () | Out-Null
40
41
Start-Sleep - Seconds 1
41
42
$Service.Delete () | Out-Null
42
- $Service.Dispose () | Out-Null
43
+ $Service.Dispose () | Out-Null
43
44
}
44
45
}
45
46
END {
46
47
if (! (Get-Service $ServiceName - ErrorAction SilentlyContinue)) {
47
48
Write-Output " Deleted service: $ServiceName "
48
49
}
49
50
}
50
- }
51
+ }
0 commit comments