Returning an object from PowerShell cmdlet
You don't ever need to return a value from the Cmdlet.ProcessRecord
method. This method has it's specific place and way of use in the PowerShell cmdlet processing lifecycle.
Passing objects down the cmdlet processing pipeline is handled by the framework for you. The same way as your cmdlet instance gets the input data it can send the data to the output for further processing. Passing objects to the output is done using the Cmdlet.WriteObject
method inside of input processing methods, that is BeginProcessing
, ProcessRecord
and EndProcessing
.
To pass the constructed rptFileSettings
object to your cmdlet output you only need to do this:
protected override void ProcessRecord(){ ReportFileSettings rptFileSettings = new ReportFileSettings(); ... WriteObject(rptFileSettings);}