1

I have prepared a PowerShell script in PS 3.0 and when I am executing it in PS 2.0 I am getting an error saying "A positional parameter cannot be found that accepts the argument -tail".

The same command is being executed well in PS 3.0. Below is my command.

get-content '\\mtrlpqdc2c4-035\D$\HPBSM\log\odb\jvm_statistics.log' -Tail 1

Is there any other parameter that I can use instead of "-Tail"

1
  • I have tried "select -last 1". For this also I got the same output. Commented Apr 4, 2019 at 13:42

1 Answer 1

3

No, Get-Content did not add the Tail parameter until v3.

A fast workaround:

(Get-Content -Path $path)[-1]

I believe Tail does not gather the content of the entire file and select n lines like my workaround does, so this method will be significantly slower on a large enough file unless you implement your own method of getting the end of a file.

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

1 Comment

This Worked like a Charm.

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.