Pergunta

In a powershell cmdlet that I am writing in C#, I need to get the name of the script that has called me.

I have derived my cmdlet class from PSCmdlet; there is a ton of information attached to this class at runtime, but I don't see where I can get the information I am looking for.

Is it possible to get the script name? If so, where does it live?

Foi útil?

Solução 2

Thanks, mjolinor... put me on the right path.

MyInvocation.InvocationName gives you the name of the command that the cmdlet was invoked under, but the calling script name is right close by...

I found what I was looking for here (from within the PSCmdlet-derived class):

var callingScript = MyInvocation.ScriptName;

It contains the full path of the script that called the cmdlet.

Outras dicas

The automatic variable $MyInvocation should contain the name of the script in the InvocationName property.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top