In the foreach loop:

([text.encoding] | gm -Static -MemberType Properties).Name) didn't work in PowerShell 2.0

So had to change it to ($global:enc in [text.encoding] | gm -Static -MemberType Properties | select Name) and then refer to the variable as $global:enc.Name.