⚡ PowerShell 5.1+

Get IIS log files Size Report

Reports how much disk space IIS log files is currently using, read-only (no deletion).

By WindowsScripting.com · 806 B
Get-IISLogsSizeReport.ps1
<#
.SYNOPSIS
    Reports how much disk space IIS log files is using.

.DESCRIPTION
    Recursively sums the size of every file under IIS log files and prints
    a human-readable total, without deleting anything.

.EXAMPLE
    .\Get-IISLogsSizeReport.ps1
#>

[CmdletBinding()]
param()

$targetPath = 'C:\inetpub\logs\LogFiles'

if (-not (Test-Path $targetPath)) {
    Write-Host "$targetPath does not exist on this machine." -ForegroundColor Yellow
    return
}

$files = Get-ChildItem -Path $targetPath -Recurse -File -Force -ErrorAction SilentlyContinue
$totalBytes = ($files | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum

Write-Host "$targetPath" -ForegroundColor Cyan
Write-Host "  Files: $($files.Count)"
Write-Host "  Total size: $([math]::Round($totalBytes / 1MB, 2)) MB"