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

**URL:** <https://forums.powershell.org/t/can-i-get-a-mocks-name-from-inside-the-mock/19263>\
**Category:** Pester\
**Created:** [May 6, 2022, 9:03pm UTC](https://forums.powershell.org/t/can-i-get-a-mocks-name-from-inside-the-mock/19263 "2022-05-06T21:03:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chscott](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/chscott/32/2356_2.png) [@chscott](https://forums.powershell.org/u/chscott)\
**Post date:** [May 6, 2022, 9:03pm UTC](https://forums.powershell.org/t/can-i-get-a-mocks-name-from-inside-the-mock/19263/1 "2022-05-06T21:03:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [May 7, 2022, 7:07am UTC](https://forums.powershell.org/t/can-i-get-a-mocks-name-from-inside-the-mock/19263/2 "2022-05-07T07:07:16Z")

</div>

@chscott Welcome to [PowerShell.org](http://PowerShell.org) forums.

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

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

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:13pm UTC](https://forums.powershell.org/t/can-i-get-a-mocks-name-from-inside-the-mock/19263/3 "2024-05-16T21:13:23Z")

</div>


