0

Typically in my scripts, I use the following to get the name of the current script (without the extension):

$baseName = (Get-Item $PSCommandPath).BaseName

For some reason, this (and every other way I can think of to get the name of the running script) is not working when the script is packaged as an executable. I am using Powershell Pro Tools with VS Code to package the script. While I could just hard code the base code, I would prefer not to. Is there anything I can do to get around this? Any way to get the name of the executable, even though it is in reality a script?

Thanks

3
  • Hmm, that's interesting... I wonder if you'd have to to read it as a subexpression, or it's just not taking the variable period. Commented Feb 21, 2021 at 4:50
  • Using PSPTools, or PS2EXE, is the same result. Take a step back for a moment and think about your use case. You are checking for a script path, but running an executable, which is a process, not a script. So, getting the command path of your executable means looking at your executable process specific. What are you doing with that name, thus the need to capture it? Commented Feb 21, 2021 at 5:10
  • Does this answer your question? Is there a way to properly access the isnetworkdeployed property from a complied EXE (using Quest PowerGUI)? Commented Feb 21, 2021 at 9:54

1 Answer 1

0

Ended up using $baseName = [System.Diagnotics.Process]::GetCurrentProcess.Name. That seemed to do the trick.

Sign up to request clarification or add additional context in comments.

Comments

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.