The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, ...

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 from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.