The problem for me was that my powershell scripts were not saved with the "UTF8 with BOM" encoding. I was getting the error when only using the UTF8 encoding. I fought a hard battle to figure this out.