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

Time:09-16

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?

CodePudding user response:

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.

  • If you want to count the number of objects (AppX packages):
(Get-AppPackage).Count
  • If you wanted to count the number of objects (AppX packages) whose .Name property contains neither the empty string nor $null, use the following - but note that this should be true of all objects returned by Get-AppPackage:
(Get-AppPackage | Where-Object Name).Count
  • Related