문제

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?

도움이 되었습니까?

해결책 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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top