PoshCode Logo PowerShell Code Repository

Get-ScriptDirectory by Andy Arismendi 5 years ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2887"></script>download | new post

Returns the directory that current script is running in.

  1. function Get-ScriptDirectory {  
  2.         $invocation = (Get-Variable MyInvocation -Scope 1).Value
  3.         $script = [IO.FileInfo] $invocation.MyCommand.Path
  4.         if ([IO.File]::Exists($script)) {
  5.         Return (Split-Path $script.Fullname)
  6.         } else {
  7.                 return $null
  8.         }
  9. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

Remember me