2

Is there a possibility to dynamically add the .ps1 filename to the scripts help section?

I am trying to put examples in the help section of my script and always show the current filename, in case a customer changes it.

Like this:

<#
.EXAMPLE
 .\$name -param1 xxx
\#>

and if i run

get-help .\my_script.ps1 -examples

the output should look like

EXAMPLE
.\my_script.ps1 -param1 xxx

I am not sure if this is possible inside of a comment

but get-help has the possibility to detect the filename

if you run

get-help .\filename.ps1

its name is added to the syntax section

you could also run

get-help .\filename.ps1 | select *

and you'll see that the name is part of the output so maybe this is usable somehow?

thanks

1 Answer 1

3

To produce the script's path and filename

$pscommandpath

If you want JUST the filename:

Split-Path -leaf $PSCommandpath
Sign up to request clarification or add additional context in comments.

1 Comment

nope sorry, this does not work inside the example area, I've already tried that. this just works in the normal script area

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.