May I please ask, did this ever run successfully? Dumb question: Are you running as a user that has rights to all database objects? I would comment out all but one or two flags and uncomment one at a time to reveal what exactly breaks. It might help to add $_.name to the output to see what's executing.