## Ozzie.eu

Love to code although it bugs me.

As you might have read, I’m a fan of getting things done. Having to develop a quick batch solution for some data copying between different SQL Server databases, I chose to use Powershell scripting and the Invoke-SqlCmd cmdlet. However I was faced with unexpected errors for something as trivial as an export/import job. The first version of my script went like the example below:

On execution, it read the first record correctly and then aborted with the following error:

Invoke-Sqlcmd : The WriteObject and WriteError methods cannot be called
from outside the overrides of the BeginProcessing, ProcessRecord,
and EndProcessing methods, and they can only be called