-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClearInv-Win7.ps1
58 lines (49 loc) · 1.27 KB
/
ClearInv-Win7.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<#
.SYNOPSIS
Deleted List of WMI CLass and instance
.DESCRIPTION
This script is for detroy unwanted or useless WMI Class.
Be carrefeull when you do This, Destroy System class can made several damage to your system.
.NOTES
Version: 1.0
Author: Letalys
Creation Date: 27/10/2023
Purpose/Change: Initial
.LINK
Author : Letalys (https://github.com/Letalys)
#>
$VerbosePreference = 'SilentlyContinue'
Function Remove-WMIInstance{
[CmdletBinding()]
param
(
[ValidateNotNullOrEmpty()][Parameter(Mandatory=$true)][string]$ClassName
)
Write-Verbose "Deleting class $Classname ..."
if ($null -ne (Get-WmiObject $ClassName -ErrorAction SilentlyContinue)) {
try{
Remove-WmiObject $ClassName
}catch{
Write-Verbose "$Classname Error : $($_)"
}
}
else {
Write-Verbose "$ClassName not exist"
}
}
Try{
$ClassNameList = @(
"ClassName1",
"ClassName2"
)
foreach($ClassName in $ClassNameList){
Remove-WMIInstance -ClassName $ClassName
}
return 0
}catch{
Write-Host "An error occurred : "
Write-Host "$($_.InvocationInfo.ScriptLineNumber) : $($_)"
Write-Verbose $_
Write-Verbose "Return -1 for general error"
return -1
}