-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ps1
More file actions
63 lines (51 loc) · 1.91 KB
/
main.ps1
File metadata and controls
63 lines (51 loc) · 1.91 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
param(
[switch]$DryRun,
[string[]]$NugetPackages = @(),
[string]$NugetFolder = 'C:\nuget',
[int]$NugetDays = 30
)
Import-Module .\WindowsDiskCleanup\WindowsDiskCleanup.psm1 -Force
$global:WDCDryRunTotalBytes = 0
$spaceBeforeGB = Get-DiskSpace -SpaceType Free -Unit GB
Write-Host "Free Space Before: $spaceBeforeGB GB" -ForegroundColor Green
$removeCommands = @(
@{ Cmd = "Remove-TempASPNETFile"; Days = 30 },
@{ Cmd = "Remove-IISLog"; Days = 7 },
@{ Cmd = "Remove-ChromiumTempData"; Days = 60 },
@{ Cmd = "Remove-DebugDiagLogs"; Days = 60 }
)
foreach ($command in $removeCommands) {
if ($DryRun) {
write-Host "Executing $($command.Cmd) in Dry Run mode...[days>$($command.Days)]" -ForegroundColor Cyan
& $command.Cmd -Days $command.Days -DryRun
}
else {
& $command.Cmd -Days $command.Days
}
}
$effectiveNugetPackages = @($NugetPackages | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
if ($effectiveNugetPackages.Count -eq 0) {
$effectiveNugetPackages = @('*')
}
foreach ($packageName in $effectiveNugetPackages) {
$nugetParams = @{
PackageName = $packageName
NugetFolder = $NugetFolder
Days = $NugetDays
}
if ($DryRun) {
Write-Host "Executing Remove-NugetPackageVersion in Dry Run mode...[package=$packageName][days>$NugetDays]" -ForegroundColor Cyan
$nugetParams.DryRun = $true
}
Remove-NugetPackageVersion @nugetParams
}
if ($DryRun) {
$expectedSavingsGB = [math]::Round($global:WDCDryRunTotalBytes / 1GB, 2)
Write-Host "Expected Disk Space Savings: $expectedSavingsGB GB" -ForegroundColor Yellow
}
else {
$spaceAfterGB = Get-DiskSpace -SpaceType Free -Unit GB
$savingsGB = [math]::Round($spaceAfterGB - $spaceBeforeGB, 2)
Write-Host "Free Space After: $spaceAfterGB GB" -ForegroundColor Green
Write-Host "Disk Space Freed: $savingsGB GB" -ForegroundColor Yellow
}