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

Harlan
  • 133
  • 1
  • 3
  • 15
  • 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. – Abraham Zinala Feb 21 '21 at 04: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? – postanote Feb 21 '21 at 05:10
  • Does this answer your question? [Is there a way to properly access the isnetworkdeployed property from a complied EXE (using Quest PowerGUI)?](https://stackoverflow.com/questions/65040018/is-there-a-way-to-properly-access-the-isnetworkdeployed-property-from-a-complied) – iRon Feb 21 '21 at 09:54

1 Answers1

0

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

Harlan
  • 133
  • 1
  • 3
  • 15