-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClean.ps1
More file actions
50 lines (41 loc) · 1.84 KB
/
Copy pathClean.ps1
File metadata and controls
50 lines (41 loc) · 1.84 KB
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
#Cleans temp files, empties event logs
#Remove Users Temp folder
write-host 'Clear ' $env:temp -ForegroundColor green
Remove-Item $env:temp\* -Recurse -Force -ErrorAction SilentlyContinue
#Remove Windows Temp folder
write-host 'Clear ' $env:SystemRoot\temp\ -ForegroundColor Green
Remove-Item $env:SystemRoot\temp\* -Recurse -Force -ErrorAction SilentlyContinue
#Clear all eventlogs
write-host 'Clear Eventlogs' -ForegroundColor Green
$logs = get-eventlog -computername $env:COMPUTERNAME -list | foreach {$_.Log}
$logs | foreach {clear-eventlog -comp $env:COMPUTERNAME -log $_ }
get-eventlog -computername $env:COMPUTERNAME -list
#Remove IIS Log
Import-Module WebAdministration -ErrorAction SilentlyContinue
If (Get-Module WebAdministration)
{
$IISLogs = (Get-WebConfigurationProperty "/system.applicationHost/sites/siteDefaults" -name logfile.directory).Value
write-host 'Clear IIS Logs' $IISLogs -ForegroundColor Green
Remove-Item $IISLogs -Filter "*.log" -Recurse -Force -ErrorAction SilentlyContinue
}
#Remove SharePoint Log
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
If (Get-Pssnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue)
{
$SPSLog = Get-SPDiagnosticConfig
Write-host 'Clear SharePoint Logs' $SPSLog.LogLocation -ForegroundColor Green
Remove-Item $SPSLog.LogLocation -Filter "*.log" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $SPSLog.LogLocation -Filter "*.usage" -Recurse -Force -ErrorAction SilentlyContinue
}
#Remove Logs
$LogFolders = @(` 'C:\Temp\CM'
)
foreach ($LogFolder in $LogFolders)
{
If (get-item $LogFolder -ErrorAction SilentlyContinue)
{
Write-Host 'Clear Log Folder' $LogFolder -ForegroundColor Green
Remove-Item $LogFolder\* -Recurse -Force -ErrorAction SilentlyContinue
}
}