Get-CallerModuleName.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function Get-CallerModuleName {
    <#
    .SYNOPSIS
        Returns the caller's module name.

    .DESCRIPTION
        Gets the caller's module name by retrieving it from the CallStack invokation
        information.

    .EXAMPLE
        Get-CallerModuleName
    #>

    [CmdletBinding()]
    Param(
    )

    (Get-PSCallStack)[1].InvocationInfo.MyCommand.ModuleName
}