Skip to content

Commit ae10f63

Browse files
committed
Added usage examples to README and enhanced Remove-OldItem to display file size during dry run
1 parent 4a275db commit ae10f63

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,27 @@ PowerShell module for cleaning disk space.
77

88
To learn about available cmdlets head to: [**docs/Public Cmdlets**](doc/Public-Cmdlets.md)
99

10+
## Usage examples
11+
12+
```powershell
13+
# Install the module (PowerShell 5.1+ / PowerShell 7+)
14+
Install-Module -Name WindowsDiskCleanup -Scope CurrentUser
15+
16+
# Import the module into the current session
17+
Import-Module WindowsDiskCleanup
18+
19+
# List all commands provided by the module
20+
Get-Command -Module WindowsDiskCleanup
21+
22+
# Dry run - show which IIS log files would be removed older than 100 days
23+
Remove-IISLog -Days 100 -DryRun
24+
```
25+
26+
Alternatively, you can run complete cleanup with default settings:
27+
28+
```powershell
29+
cls;.\main.ps1 -DryRun
30+
```
31+
1032
## License
1133
[MIT License](LICENSE.md) © Alan Płócieniak

WindowsDiskCleanup/Public/Remove-OldItem.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function Remove-OldItem {
2424

2525
if (($now - $File.CreationTimeUtc).TotalDays -gt $Days) {
2626
if ($DryRun) {
27-
Write-Host "[Dry] Removing $($File.FullName)" -ForegroundColor Yellow
27+
$size = Get-ItemSize -Path $File.FullName -Unit MB
28+
Write-Host "[Dry] Removing $($File.FullName) [$size MB]" -ForegroundColor Yellow
2829
}
2930
else {
3031
Remove-Item -Path $File.FullName -Force -Recurse

main.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
param(
2+
[switch]$DryRun
3+
)
4+
5+
Import-Module .\WindowsDiskCleanup\WindowsDiskCleanup.psm1 -Force
6+
7+
$spaceBeforeGB = Get-DiskSpace -SpaceType Free -Unit GB
8+
Write-Host "Free Space Before: $spaceBeforeGB GB" -ForegroundColor Green
9+
10+
$removeCommands = @(
11+
@{ Cmd = "Remove-TempASPNETFile"; Days = 30 },
12+
@{ Cmd = "Remove-IISLog"; Days = 7 },
13+
@{ Cmd = "Remove-ChromiumTempData"; Days = 60 },
14+
@{ Cmd = "Remove-DebugDiagLogs"; Days = 60 }
15+
)
16+
17+
foreach ($command in $removeCommands) {
18+
if ($DryRun) {
19+
write-Host "Executing $($command.Cmd) in Dry Run mode...[days>$($command.Days)]" -ForegroundColor Cyan
20+
& $command.Cmd -Days $command.Days -DryRun
21+
}
22+
else {
23+
& $command.Cmd -Days $command.Days
24+
}
25+
}
26+
27+
$spaceAfterGB = Get-DiskSpace -SpaceType Free -Unit GB
28+
$savingsGB = [math]::Round($spaceAfterGB - $spaceBeforeGB, 2)
29+
30+
Write-Host "Free Space After: $spaceAfterGB GB" -ForegroundColor Green
31+
Write-Host "Disk Space Freed: $savingsGB GB" -ForegroundColor Yellow

0 commit comments

Comments
 (0)