Powershell Script fails after accessing Array.Length Property

Question:

Can someone explain why this script throws an exception?

Basically, I am creating an array of numbers, formatting the array and then checking its length and formatting it again.

The first format succeeds, but the second format throws an exception.

Answer:

That’s definitely weird. As a workaround you can use

which seems to work even after accessing members of $byteArray.

Another possible workaround might be to save the formatted string to a variable and re-use it.

As for why it doesn’t work after accessing the Length property I have no idea.

Source:

Powershell Script fails after accessing Array.Length Property by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply