Saturday, March 24, 2012

Get Current Script Directory Path in PowerShell

While executing a script, one might need to find out where exactly the script being executed is located. After some research, the following link came up.

This achieves it by creating the following function.


  1. function Get-ScriptDirectory
  2. {
  3. $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  4. Split-Path $Invocation.MyCommand.Path
  5. }

No comments: