0

I've the following result from a PowerShell array:

Level
-----
    0

How can I convert it to an Int to retrieve only the value which is the number under the level?

2
  • 2
    $myArray.Level should do. What you're seeing is an object with a property (probably). Commented Dec 12, 2018 at 10:35
  • 1
    Alternatively use $myArray | Select-Object -Expand Level. Commented Dec 12, 2018 at 10:38

1 Answer 1

1

Like Ansgar said, use Select-Object with the -ExpandProperty parameter. I like that best as if .value isnt there for some reason it wont error out.

If it MUST be a INT then you can cast it like this:

[int]($MyArray | select -ExpandProperty Level)
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.