Can I get a mock's name from inside the mock?

In a normal function, you can use $MyInvocation.MyCommand to get the function’s name, but this returns $null in a mock. Is there any way to get the mock’s name in a similar manner?

@chscott Welcome to forums.

Was trying to figure out and one option I found is to use Meta Data builtin variable.

Mock -CommandName "Get-Process" { Write-Host "Mocking $(${Meta data}.Name)" }
1 Like