Pester, mock remote or unavailable cmdlets

Hannes Palmquist
Senior Consultant CloudThere are a lot of forum post of people having a hard time mocking some cmdlets, either it is remote cmdlets imported by a session that is not available during testing, cmdlets that are not present on the development machine or simply some built in cmdlets that are hard to mock like Import-PSSession, Invoke-Command etc.
Mocking a cmdlet that are unavailable on the development machine is quite straight forward by just declaring a dummy function before the mock.
The same method can be applied when mocking a built in cmdlet that will fail parameter validation which happends even though the cmdlets is mocked
The error states that Import-PSSession requires valid PSSession object to be passed to the session parameter. Again we need to define a dummy function that don't expects a PSSession object to be passed.