Does anyone know whether its possible mark a post as a "sticky"? It would be
really nice to start a FAQ.
Justin the MyInvocation variable is what you want. The state of this
variable depends on the context in which its called which makes it somewhat
confusing.
Run this script it should help explain as you can see the output is
different depending on whether you are at script of function scope.
function test
{
echo "Entering function Test"
echo "`$MyInvocation.InvocationName is $($MyInvocation.InvocationName)"
echo "`$MyInvocation.MyCommand.name is $($MyInvocation.MyCommand.name)"
echo "`$MyInvocation.ScriptName is $($MyInvocation.ScriptName)"
echo "`$MyInvocation.MyCommand.path is $($MyInvocation.MyCommand.path)"
echo "`$pwd.path $($pwd.path)"
echo "Leaving function Test"
}
echo "Entering MyInvocation Test Scriptblock"
echo "`$MyInvocation.InvocationName is $($MyInvocation.InvocationName)"
echo "`$MyInvocation.MyCommand.name is $($MyInvocation.MyCommand.name)"
echo "`$MyInvocation.ScriptName is $($MyInvocation.ScriptName)"
echo "`$MyInvocation.MyCommand.path is $($MyInvocation.MyCommand.path)"
echo "`$pwd.path $($pwd.path)"
echo "Calling Test"
test
echo "Leaving MyInvocation Test Scriptblock"
"Justin Rich" wrote:
> i want to find where my script is located... so when i run a command like...
>
> c:\>powershell c:\myscripts\thescript.ps1
>
> i'd get back either c:\myscripts or c:\myscripts\thescript.ps1
>
> i found this
> $myinvocation.mycommand.path but that returns the current location (in this
> case, c:\)
> as does $(pwd).path
>
> any other suggestions?
>
> Thanks
> Justin
>
>
>
>