-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanPC.PS1
More file actions
95 lines (61 loc) · 2.42 KB
/
Copy pathCleanPC.PS1
File metadata and controls
95 lines (61 loc) · 2.42 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
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
#
#
# Clean Windows temp folders
#
#
#
#
#
########## OPTIONS ##################
Function CleanPC{
[CmdletBinding()]
Param (
[bool]$empty_recycle = $true,
[DateTime]$limit = (Get-Date).AddDays(-1)
)
$folders = @(“C:\Windows\Temp\*”, “C:\Windows\Prefetch\*”,
“C:\Documents and Settings\*\Local Settings\temp\*”,
“C:\Users\*\Appdata\Local\Temp\*”,
"C:\Users\*\AppData\Local\Temp\Temporary Internet Files\Content.IE5\*",
"C:\Users\*\AppData\Local\Google\Chrome\User Data\Default\Cache\*",
"C:\Users\*\AppData\Local\Spotify\Data\*",
"C:\Users\*\AppData\Local\Google\Chrome\User Data\Default\Cache\*",
"C:\Users\*\AppData\Local\Microsoft\Office\*\OfficeFileCache\*",
"C:\Users\*\AppData\Local\Microsoft\Office\*\Lync\Tracing\*"
)
$exclude = @("C:\Users\twheeler\AppData\Local\Microsoft\Office\*\Lync\Tracing\WPPMedia","C:\Users\twheeler\AppData\Local\Microsoft\Office\*\Lync\Tracing\OCAddin")
#####################################
$total = 0;
function dataOut {
param(
[string]$path,
[string]$size
)
$size = "{0:N2}" -f ($size / 1MB)
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Size($size + " MB")
$obj | Add-Member NoteProperty Path($path)
$obj | fl
}
write-host -ForegroundColor Green "removing files created before" $limit
foreach($item in $folders){
if( (test-path -Path $item) -eq $true){
$colItems = (Get-ChildItem $item -ErrorAction SilentlyContinue | Measure-Object -property length -sum -ErrorAction SilentlyContinue)
$total = $total + $colItems.sum
dataOut $item $colItems.sum
Get-ChildItem -Path $item -Recurse -Force -ErrorAction SilentlyContinue | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -Exclude $exclude
}
}
$totalsize = "{0:N2}" -f ($total / 1MB) + " MB"
Write-host "-----------------------------------------------------------"
write-host -ForegroundColor Yellow " Cleaned a total of $totalsize"
Write-host "-----------------------------------------------------------"
Write-output "-----------------------------------------------------------"
if($empty_recycle -eq $true){
Write-output "Emptying recycle bin...."
if( (test-path 'C:\$Recycle.Bin') -eq $true){
Remove-Item -force -Recurse 'C:\$Recycle.Bin'
}
}
Clear-EventLog -log system,application,security
}