Agent crashes when large Powershell script is executed