Noob Question - - How to call InvocationInfo.PSScriptRoot for a PowerShell Module

John McCrae 0 Reputation points

I am teaching myself C# by building a PowerShell module. I want to retrieve the PSScriptRoot property from the InvocationInfo class but it appears to be something that is called indirectly. Does anyone have guidance on a) how to invoke it or b) how to use it to spit out the script root?

A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,313 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rafael da Rocha 4,961 Reputation points

    You can use the automatic variable $PSScriptRoot anytime a script is running.
    If you want to see the output, just

    Write-Host $PSScriptRoot

    Or $MyInvocation.PSScriptRoot , that will have information about the calling script and not the current script

    Additional information about all the automatic variables is available on Learn:

    0 comments No comments