Bug: Workflow -> InlineScript -> Function -> Function -> Write-Verbose throws an uncatchable and fatal exception
I've blogged about this with full examples here: https://www.codykonior.com/2016/08/31/if-you-dont-mind-me-saying-powershell-workflows-are-awfully-broken/
- If you have a workflow and call it with -Verbose
- If that workflow has an InlineScript which calls a function
- And that function calls another function which does a Write-Verbose
A terminating, uncatchable exception is thrown:
Object reference not set to an instance of an object.
+ CategoryInfo : ResourceUnavailable: (:) , ParentContainsErrorRecordException
+ FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException
+ PSComputerName : [localhost]
It seems to be with how Write-Verbose gets overridden in workflows to prefix output with the computer name it's running on. Creating a Write-Verbose wrapper around itself alleviates the issue.