Recently, I have been writing/ reading a lot of Pester tests (both Unit and Integration) for infrastructure validation. One of the classic limitation hit during mocking with Pester is that you can have different mocks based on different arguments to a parameter (e.g using parameterFilter with Mock ) but not based on a counter. For Example - See below, I have two mocks for Get-Process cmdlet based on the name passed to it. Mock -CommandName Get-Service -ParameterFilter { $Name -eq 'winrm' } -mockwith {[PSCustomObjet]@{Status='Running'} } Mock -CommandName Get-Service -ParameterFilter { $Name -eq 'bits' } -mockwith { [PSCustomObjet]@{Status='Stopped' } This is really helpful, but there is a case where we want different mocks to occur based on a an incremental counter (number of times) a function/Cmdlet etc. are called in our script.
Infra + Dev's ramblings