Archive for the ‘PowerShell’ Category

PowerShell Dev Tip: Counting the number of lines in a VS project

Yesterday, I was confronted with the issue that I had to know the number of lines in a C# project to estimate the complexity of a rewrite. In order to get the job done, I wrote a little PowerShell script that counts all the source lines in a given project folder. Writing this in the PowerShell is remarkable easy thanks to the Measure-Object command.

Get-ChildItem -recurse -filter "*.cs" . | Foreach-Object {
	$lines = Get-Content $_.FullName | Measure-Object -line
	$fileAnalysis = New-Object -TypeName PSObject
	$fileAnalysis | Add-Member -MemberType NoteProperty -Name "Name" -Value $_.FullName
	$fileAnalysis | Add-Member -MemberType NoteProperty -Name "Lines" -Value $lines.Lines
	Write-Output $fileAnalysis
} | Export-Csv -NoTypeInformation -Delimiter ";" result.csv
Categories: PowerShell