I want to write a cmdlet that changes its behavior depending on its pipeline position. Simplyfied example:
Get-XYZObject | Rename-XYZObject
If the cmdlet is the last in the pipeline it should work directly on a database object.
Get-XYZObject | Rename-XYZObject | Set-XYZValue | Write-XYZObject
If it is not the endpoint it should pipe the object.
Is there a solution without providing a parameter to switch the behaviour?
I searched the web for a solution and read some tutorials about pipeline but found nothing. That could have two reasons:
- I do not know what to search for.
- It is just not possible.
I tend to the second cause the case
$renamedObject = Get-XYZObject | Rename-XYZObject
could be a problem. Would be nice if someone can clarify that.