Home > OS >  What is the Powershell equivalent to C's argv[0]?
What is the Powershell equivalent to C's argv[0]?

Time:05-12

That is to say - how can I get the name of the called script from within said script? For example, if I do this:

.\foobar.ps1 -param1 10 -param2 20

How would I get the string 'foobar.ps1'?

CodePudding user response:

There is an automatic variable that provides this information: $PSCommandPath.

This gives the full path to the script, but if you want just the file name, you can use Split-Path to get just that part:

Split-Path -Path $PSCommandPath -Leaf

  • Related