Last active
May 20, 2021 13:34
-
-
Save moiaune/3dbb024814e65605d09d82ca2a4af113 to your computer and use it in GitHub Desktop.
Get-LinesOfCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get lines of code in a powershell project | |
# Inspiration: https://www.limilabs.com/blog/source-lines-of-code-count-using-powershell | |
function Get-LinesOfCode { | |
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[string] | |
$Path = "." | |
) | |
$Path = Resolve-Path -Path $Path | |
$linesOfCode = Get-ChildItem -Path $Path -Filter *.ps1 -Recurse | | |
Select-String "^\s*$" -NotMatch | # Filter out blank lines | |
Select-String "^\s*#" -NotMatch | # Filter out lines starting with comments | |
Select-String "^\s*<#" -NotMatch | # Filter out lines starting with '<#' (multiline-line comments) | |
Select-String "^\s*\.\w*" -NotMatch # Filter out lines starting with . and then som characters (e.g .PARAMETER) | |
Write-Output $linesOfCode.Count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment