Krank
Krank

Reputation: 111

Convert PowerShell array to integer

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?

Upvotes: 0

Views: 5523

Answers (1)

Eric Weintraub
Eric Weintraub

Reputation: 1027

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)

Upvotes: 1

Related Questions