-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoshDellDBUtil.psm1
59 lines (55 loc) · 3.3 KB
/
PoshDellDBUtil.psm1
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
59
function Invoke-PoshDDClean {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[String]$ComputerOU,
[Parameter(Mandatory=$false,Position=1)]
[Switch]$Clean
)
$Computers = Get-ADComputer -Filter * -SearchBase "$($ComputerOU)" | Select-Object -Property Name | Sort-Object -Property Name
foreach ($Computer in $Computers) {
if (Test-Connection -ComputerName $Computer.Name -Quiet -Count 2 -ErrorAction SilentlyContinue) {
Write-Host "$($Computer.Name):" -ForegroundColor White -BackgroundColor DarkGreen
Invoke-Command -ComputerName $Computer.Name -ErrorAction SilentlyContinue -ScriptBlock {
param($Clean)
Write-Verbose "Scan"
if(Test-Path -Path "C:\Windows\Temp\DBUtil_2_3.Sys" -PathType Leaf){
Write-Host "Windows->Temp folder: DBUtil_2_3.Sys found!" -ForegroundColor White -BackgroundColor DarkRed
if ($Clean) {
Write-Verbose "Clean: Windows->Temp"
Write-Host "Removing DBUtil_2_3.Sys..." -ForegroundColor Yellow
Remove-Item -Path "C:\Windows\Temp\DBUtil_2_3.Sys"
if(!(Test-Path -Path "C:\Windows\Temp\DBUtil_2_3.Sys" -PathType Leaf)){
Write-Host "Deleted successfully!" -ForegroundColor White -BackgroundColor DarkGreen
} else {
Write-Host "Error!" -ForegroundColor White -BackgroundColor DarkRed
}
}
} else {
Write-Host "DBUtil_2_3.Sys not found at Windows->Temp!" -ForegroundColor White -BackgroundColor DarkGreen
}
$Users = Get-ChildItem -Path "C:\Users" -Directory -Exclude Default,Public
foreach($User in $Users){
if(Test-Path -Path "C:\Users\$($user.Name)\AppData\Local\Temp\DBUtil_2_3.Sys"){
Write-Host "$($user.Name)->Temp folder: DBUtil_2_3.Sys found!" -ForegroundColor White -BackgroundColor DarkRed
if ($Clean) {
Write-Verbose "Clean: User->Temp"
Write-Host "Removing DBUtil_2_3.Sys..." -ForegroundColor Yellow
Remove-Item -Path (Get-ChildItem -Path "C:\Users\$($user.Name)\AppData\Local\Temp" -Filter DBUtil_2_3.Sys -Recurse -ErrorAction SilentlyContinue -Force).FullName
if(!(Test-Path -Path "C:\Users\$($user.Name)\AppData\Local\Temp\DBUtil_2_3.Sys")){
Write-Host "Deleted successfully!" -ForegroundColor White -BackgroundColor DarkGreen
} else {
Write-Host "Error!" -ForegroundColor White -BackgroundColor DarkRed
}
}
} else {
Write-Host "DBUtil_2_3.Sys not found at $($user.Name)->Temp!" -ForegroundColor White -BackgroundColor DarkGreen
}
}
} -ArgumentList $Clean
} else {
Write-Host "$($Computer.Name) not reachable!" -ForegroundColor White -BackgroundColor DarkRed
}
}
}