0

I have read here that when we read in the contents of .txt file using the get-content cmdlet into a variable, it is saved as an Array:

When Get-Content reads a text file and stashes the contents in a variable, the data is stored as an array, with each line in the file (determined by the presence of a carriage return-linefeed character) representing a single item in the array.

I read in the contents of the text file using get-content, and 4 lines were printed to the powershell console.

Then I read in the contents of the same file into a variable ips, and then used the ips.length as well as ips.count, 7 was printed out.

What am I missing?

enter image description here

3
  • Interesting, but without an MCVE (Minimal, Complete, and Verifiable Example) it's hard to diagnose this problem. Commented Aug 17, 2016 at 5:30
  • 5
    There is a blank line at the top and two at the bottom of your content. These, plus the four lines of content = count/length 7 Commented Aug 17, 2016 at 5:35
  • @Tibrogargan Please post that as an answer. I can't upvote your comment due to low votes I have. Commented Aug 17, 2016 at 6:45

1 Answer 1

1

There is a blank line at the top and two at the bottom of your content. These, plus the four lines of content = count/length 7

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.