Skip to content

Instantly share code, notes, and snippets.

@jehugaleahsa
Created August 18, 2017 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jehugaleahsa/7f1b7cc5ffdb50fd023842b7485e8dea to your computer and use it in GitHub Desktop.
Save jehugaleahsa/7f1b7cc5ffdb50fd023842b7485e8dea to your computer and use it in GitHub Desktop.
A simple PowerShell script to count the lines of code in a solution
$path = "C:\path\to\solution\folder"
$files = Get-ChildItem -Path $path -Include *.cs,*.ts,*.vb -Recurse `
| ? { $_.FullName -notmatch ".*\\obj\\.*" } `
| ? { $_.FullName -notmatch ".*\\node_modules\.*" }
$shortNames = $files | % {
$fullName = $_.FullName
$lines = [System.IO.File]::ReadAllLines($fullName)
$lines = $lines | ? { -not [System.String]::IsNullOrWhiteSpace($_) }
$data = @{};
$data.Name = $_.Name
$data.LineCount = $lines.Length
New-Object -TypeName PSObject -Property $data
} | Sort-Object -Property LineCount -Descending
#$biggest = $shortNames | Select-Object -First 100
$count = $shortNames | Measure-Object -Sum -Average -Property LineCount
Write-Host $count.Sum $count.Average
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment