forked from MicksITBlogs/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CiscoJabberChatCleanup.ps1
278 lines (232 loc) · 7.52 KB
/
CiscoJabberChatCleanup.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<#
.SYNOPSIS
Delete Cisco Jabber Chat History
.DESCRIPTION
Deletes the files and folder that contain the Cisco Jabber chat history
.PARAMETER SecureDelete
Implement Secure Deletion of files and folders
.PARAMETER SecureDeletePasses
Number of secure delete passes
.EXAMPLE
Delete Cisco Jabber chat without secure delete
powershell.exe -file CiscoJabberChatCleanup.ps1
Delete Cisco Jabber chate with secure delete
powershell.exe -file CiscoJabberChatCleanup.ps1 -SecureDelete -SecureDeletePasses 3
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.3.131
Created on: 12/13/2016 12:20 PM
Updated on: 12/27/2018 3:34 PM
Created by: Mick Pletcher
Filename: CiscoJabberChatCleanup.ps1
===========================================================================
#>
[CmdletBinding()]
param
(
[switch]$SecureDelete,
[string]$SecureDeletePasses = '3'
)
function Close-Process {
<#
.SYNOPSIS
Stop ProcessName
.DESCRIPTION
Kills a ProcessName and verifies it was stopped while reporting it back to the screen.
.PARAMETER ProcessName
Name of ProcessName to kill
.EXAMPLE
PS C:\> Close-ProcessName -ProcessName 'Value1'
.NOTES
Additional information about the function.
#>
[CmdletBinding()][OutputType([boolean])]
param
(
[ValidateNotNullOrEmpty()][string]$ProcessName
)
$Process = Get-Process -Name $ProcessName -ErrorAction SilentlyContinue
If ($Process -ne $null) {
$Output = "Stopping " + $Process.Name + " process....."
Stop-Process -Name $Process.Name -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
$TestProcess = Get-Process $ProcessName -ErrorAction SilentlyContinue
If ($TestProcess -eq $null) {
$Output += "Success"
Write-Host $Output
Return $true
} else {
$Output += "Failed"
Write-Host $Output
Return $false
}
} else {
Return $true
}
}
function Get-Architecture {
<#
.SYNOPSIS
Get-Architecture
.DESCRIPTION
Returns whether the system architecture is 32-bit or 64-bit
.EXAMPLE
Get-Architecture
.NOTES
Additional information about the function.
#>
[CmdletBinding()][OutputType([string])]
param ()
$OSArchitecture = Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture
$OSArchitecture = $OSArchitecture.OSArchitecture
Return $OSArchitecture
#Returns 32-bit or 64-bit
}
function Get-RelativePath {
<#
.SYNOPSIS
Get the relative path
.DESCRIPTION
Returns the location of the currently running PowerShell script
.NOTES
Additional information about the function.
#>
[CmdletBinding()][OutputType([string])]
param ()
$Path = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"
Return $Path
}
function Open-Application {
<#
.SYNOPSIS
Open Application
.DESCRIPTION
Opens an applications
.PARAMETER Executable
A description of the Executable parameter.
.PARAMETER ApplicationName
Display Name of the application
.PARAMETER Process
Application Process Name
.EXAMPLE
PS C:\> Open-Application -Executable 'Value1'
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[string]$Executable,
[ValidateNotNullOrEmpty()][string]$ApplicationName
)
$Architecture = Get-Architecture
$Uninstall = Get-ChildItem -Path REGISTRY::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
If ($Architecture -eq "64-bit") {
$Uninstall += Get-ChildItem -Path REGISTRY::"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
}
$InstallLocation = ($Uninstall | ForEach-Object { Get-ItemProperty $_.PsPath } | Where-Object { $_.DisplayName -eq $ApplicationName }).InstallLocation
If ($InstallLocation[$InstallLocation.Length - 1] -ne "\") {
$InstallLocation += "\"
}
$Process = ($Executable.Split("."))[0]
$Output = "Opening $ApplicationName....."
Start-Process -FilePath $InstallLocation$Executable -ErrorAction SilentlyContinue
Start-Sleep -Seconds 5
$NewProcess = Get-Process $Process -ErrorAction SilentlyContinue
If ($NewProcess -ne $null) {
$Output += "Success"
} else {
$Output += "Failed"
}
Write-Output $Output
}
function Remove-ChatFiles {
<#
.SYNOPSIS
Delete Jabber Chat Files
.DESCRIPTION
Deletes Jabber chat files located at %USERNAME%\AppData\Local\Cisco\Unified Communications\Jabber\CSF\History and verifies they were deleted
.EXAMPLE
PS C:\> Remove-ChatFiles
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param ()
$Users = Get-ChildItem -Path $env:HOMEDRIVE"\users" -Exclude 'Administrator', 'public', 'iCreateService', 'sccmadmin', 'Default'
foreach ($User in $Users) {
#Get Jabber Chat history files
$History = $User.FullName + '\AppData\Local\Cisco\Unified Communications\Jabber\CSF\History'
$ChatHistoryFiles = Get-ChildItem -Path $History -Filter *.db
If ($ChatHistoryFiles -ne $null) {
foreach ($File in $ChatHistoryFiles) {
$Output = "Deleting " + $File.Name + "....."
If ($SecureDelete.IsPresent) {
$RelativePath = Get-RelativePath
$sDelete = [char]34 + $env:windir + "\system32\" + "sdelete64.exe" + [char]34
$Switches = "-accepteula -p" + [char]32 + $SecureDeletePasses + [char]32 + "-q" + [char]32 + [char]34 + $File.FullName + [char]34
$ErrCode = (Start-Process -FilePath $sDelete -ArgumentList $Switches -Wait -PassThru).ExitCode
If (($ErrCode -eq 0) -and ((Test-Path $File.FullName) -eq $false)) {
$Output += "Success"
} else {
$Output += "Failed"
}
} else {
Remove-Item -Path $File.FullName -Force | Out-Null
If ((Test-Path $File.FullName) -eq $false) {
$Output += "Success"
} else {
$Output += "Failed"
}
}
Write-Output $Output
}
} else {
$Output = "No Chat History Present"
Write-Output $Output
}
}
}
function Remove-MyJabberFilesFolder {
<#
.SYNOPSIS
Delete MyJabberFiles Folder
.DESCRIPTION
Delete the MyJabberFiles folder stores under %USERNAME%\documents and verifies it was deleted.
.EXAMPLE
PS C:\> Remove-MyJabberFilesFolder
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param ()
$Users = Get-ChildItem -Path $env:HOMEDRIVE"\users" -Exclude 'Administrator', 'public', 'iCreateService', 'sccmadmin', 'Default'
foreach ($User in $Users) {
$Folder = $User.FullName + '\Documents\MyJabberFiles'
$MyJabberFilesFolder = Get-Item $Folder -ErrorAction SilentlyContinue
If ($MyJabberFilesFolder -ne $null) {
$Output = "Deleting " + $MyJabberFilesFolder.Name + "....."
Remove-Item -Path $MyJabberFilesFolder -Recurse -Force | Out-Null
If ((Test-Path $MyJabberFilesFolder.FullName) -eq $false) {
$Output += "Success"
} else {
$Output += "Failed"
}
Write-Output $Output
} else {
$Output = "No MyJabberFiles folder present"
Write-Output $Output
}
}
}
Clear-Host
#Kill Cisco Jabber Process
$JabberClosed = Close-Process -ProcessName CiscoJabber
#Delete .DB files from each %USERNAME%\AppData\Local\Cisco\Unified Communications\Jabber\CSF\History
Remove-ChatFiles
#Delete each %USERNAME%\documents\MyJabberFiles directory
Remove-MyJabberFilesFolder
#Reopen Jabber if it was open
If ($JabberClosed -eq $true) {
Open-Application -ApplicationName "Cisco Jabber" -Executable CiscoJabber.exe
}