powershellmeasure-object

Powershell: How can I avoid counting enters (blanked line) of output from a command?


This is my code to count lines, I only have 69 lines which has a value on each line:

Get-AppPackage | Select-Object -Property name, publisherid | Measure-Object -Property name -line

Output:

Lines Words Characters Property
----- ----- ---------- --------
   71                  Name

But it's counting enters as well which I don't need them.

Help?


Solution

  • Building on the helpful comments:

    This is my code to count lines

    Your code doesn't count lines. It counts the number of .Name property values whose stringified representation results in non-empty strings, because you're combining Measure-Object's
    -Line switch with (non-string) object input and a -Property argument.

    (Get-AppPackage).Count
    
    (Get-AppPackage | Where-Object Name).Count