Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Script name in Powershell

Tags:

powershell

Is there any other way except $MyInvocation.InvocationName in powershell to get the script name? As i need to turn my script in an exe and in that case it doesnt work on that exe.

like image 411
Abhishek_Mishra Avatar asked Feb 01 '12 11:02

Abhishek_Mishra


People also ask

What is $_ called in PowerShell?

The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.

Why we use $_ in PowerShell?

$_ is a variable created by the system usually inside block expressions that are referenced by cmdlets that are used with pipe such as Where-Object and ForEach-Object . But it can be used also in other types of expressions, for example with Select-Object combined with expression properties.

What is $PATH in PowerShell?

The Windows PATH environment variable is where applications look for executables -- meaning it can make or break a system or utility installation. Admins can use PowerShell to manage the PATH variable -- a process that entails string manipulation. To access the PATH variable, use: $env:Path.

What does $() mean in PowerShell?

Subexpression operator $( ) For a single result, returns a scalar. For multiple results, returns an array. Use this when you want to use an expression within another expression. For example, to embed the results of command in a string expression. PowerShell Copy.


1 Answers

I'm assuming since you convert the powershell script to an executable that you are after the location of the executable. You can get it this way:

[Environment]::GetCommandLineArgs()[0]
like image 149
jon Z Avatar answered Sep 27 '22 19:09

jon Z