1

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?

mklement0
  • 382,024
  • 64
  • 607
  • 775
BEHXAD
  • 43
  • 1
  • 6
  • 2
    I might be missing something,. but if you just want to know how many items are returned you can do this: ```(Get-AppPackage | Measure-Object).Count```, or ```@(Get-AppPackage).Length```. If they give ```71``` as well, chances are you've miscounted and there's not ```69``` :-). – mclayton Sep 13 '22 at 19:33
  • 1
    Im guessing you're looking for `Get-AppPackage | ? Name | Measure...` – Santiago Squarzon Sep 13 '22 at 19:34
  • @mclayton `Measure-Object` is counting header and 1 line(without any value, looks it presses enter ) at the end which I don't want them. although it shows 71 lines but there are only 69 lines which has a value – BEHXAD Sep 13 '22 at 19:48
  • what value are you referring to? – Abraham Zinala Sep 13 '22 at 20:53

1 Answers1

1

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
mklement0
  • 382,024
  • 64
  • 607
  • 775