Skip to content

Commit 547535c

Browse files
committed
Update Remove-WindowsServiceWMI
Rename, improve and bump
1 parent 1f3cd82 commit 547535c

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
1-
Function DeleteServiceWMI {
1+
Function Remove-WindowsServiceWMI {
22
<#
33
.SYNOPSIS
4-
Windows service removal script.
5-
4+
Removes Windows service using WMI method.
5+
66
.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+
99
.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.
1313
1414
.EXAMPLE
15-
DeleteServiceWMI -ServiceName W32Time (-ForceIf #-->use to delete)
16-
15+
Remove-WindowsServiceWMI -ServiceName W32Time -Force
16+
1717
.NOTES
18-
v2
18+
v0.1.2
1919
#>
2020
[CmdletBinding()]
2121
param(
2222
[Parameter(Mandatory = $true)]
2323
[string]$ServiceName,
2424

2525
[Parameter(Mandatory = $false)]
26-
[switch]$ForceIf
26+
[switch]$Force
2727
)
2828
BEGIN {
2929
if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
3030
Write-Host "Required service not found!" -ForegroundColor Red
31+
return
3132
}
3233
}
3334
PROCESS {
3435
$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
3738
}
3839
else {
3940
$Service.StopService() | Out-Null
4041
Start-Sleep -Seconds 1
4142
$Service.Delete() | Out-Null
42-
$Service.Dispose() | Out-Null
43+
$Service.Dispose() | Out-Null
4344
}
4445
}
4546
END {
4647
if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
4748
Write-Output "Deleted service: $ServiceName"
4849
}
4950
}
50-
}
51+
}

0 commit comments

Comments
 (0)