forked from MicksITBlogs/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CiscoJabberChat.ps1
263 lines (220 loc) · 7.17 KB
/
CiscoJabberChat.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
<#
.SYNOPSIS
Disable Cisco Jabber Chat History
.DESCRIPTION
This script will disable the Jabber chat history by setting the .DB file to read-only. It begins by killing the Jabber task, deleting the .DB file, reopening Jabber, and then setting the .DB file to read-only. The script uses this process because if the old .DB file has not been deleted before setting it to read-only, the stored conversations will be there permanently. Since the .DB file is stored in the user profile, this cannot be done in the build.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.3.131
Created on: 03/21/2017 4:21 PM
Created by: Mick Pletcher
Filename: CiscoJabberChatCleanup.ps1
===========================================================================
#>
[CmdletBinding()]
param ()
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-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 ()
#Get Jabber Chat history files
$ChatHistoryFiles = Get-ChildItem -Path $env:USERPROFILE'\AppData\Local\Cisco\Unified Communications\Jabber\CSF\History' -Filter *.db
If ($ChatHistoryFiles -ne $null) {
foreach ($File in $ChatHistoryFiles) {
$Output = "Deleting " + $File.Name + "....."
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 ()
$MyJabberFilesFolder = Get-Item $env:USERPROFILE'\Documents\MyJabberFiles' -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
}
}
function Set-DBFilePermissions {
<#
.SYNOPSIS
Set .DB File Permission
.DESCRIPTION
Make the .DB file read-only
.EXAMPLE
PS C:\> Set-DBFilePermissions
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param ()
#Get list of chat history files
$ChatHistoryFiles = Get-ChildItem -Path $env:USERPROFILE'\AppData\Local\Cisco\Unified Communications\Jabber\CSF\History' -Filter *.db
foreach ($File in $ChatHistoryFiles) {
#Set .DB file to read-only
$Output = "Setting " + $File.Name + " to Read-Only....."
$ReadOnly = Get-ItemPropertyValue -Path $File.FullName -Name IsReadOnly
If (($ReadOnly) -eq $false) {
Set-ItemProperty -Path $File.FullName -Name IsReadOnly -Value $true
$ReadOnly = Get-ItemPropertyValue -Path $File.FullName -Name IsReadOnly
If (($ReadOnly) -eq $true) {
$Output += "Success"
} else {
$Output += "Failed"
}
} else {
$Output += "Success"
}
Write-Output $Output
}
}
Clear-Host
#Kill Cisco Jabber Process
$JabberClosed = Close-Process -ProcessName CiscoJabber
#Delete .DB files from %USERNAME%\AppData\Local\Cisco\Unified Communications\Jabber\CSF\History
Remove-ChatFiles
#Delete %USERNAME%\documents\MyJabberFiles directory
Remove-MyJabberFilesFolder
#Reopen Jabber if it was open
If ($JabberClosed -eq $true) {
Open-Application -ApplicationName "Cisco Jabber" -Executable CiscoJabber.exe
}
$JabberClosed = Close-Process -ProcessName CiscoJabber
#Set the .DB file to read-only
Set-DBFilePermissions
#Reopen Jabber
If ($JabberClosed -eq $true) {
Open-Application -ApplicationName "Cisco Jabber" -Executable CiscoJabber.exe
}