Skip to content

Instantly share code, notes, and snippets.

@alastairs
Created September 13, 2011 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alastairs/1215274 to your computer and use it in GitHub Desktop.
Save alastairs/1215274 to your computer and use it in GitHub Desktop.
Function to get the directory in which this script resides.
function Get-ScriptDirectory {
$invocation = (Get-Variable MyInvocation -Scope 1).Value
$script = [IO.FileInfo] $invocation.MyCommand.Path
if ([IO.File]::Exists($script)) {
return (Split-Path $script.Fullname)
} else {
return $null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment