This is expected behavior. APIs will return whatever is written to the pipeline. If Connect-VIServer returns an object, that object will be returned along with the New-PSUAPIResponse. New-PSUAPIResponse will return an object and if it’s the only object returned it will use that for customizing the response.
It is not related to a Dashboard, but an API endpoint instead. Adam reported back, that the behavior is expected - and so I will continue to use | Out-Null to get rid of the output of Connect-VIServer.
So New-PSUApiResponse doesn’t actually return the data immediatly, but “only” builds the object, that will be returned at the end of the endpoint? And because the result of New-PSUApiResponse is not written to a variable or Out-Null the result gets to the output pipeline. Have I got it right, now?
Correct. We don’t exit early from the script block to return a result since only a single response can be returned. We wait until the scriptblock has executed entirely.