Last active
December 24, 2015 00:19
-
-
Save toenuff/6715996 to your computer and use it in GitHub Desktop.
The following snippet gets the current directory whether or not it's run from a script or a PowerShell host. I put this at the top of nearly every script I write. Blogged as powerbit #9 here: http://powertoe.wordpress.com/2012/11/02/powerbits-9-set-the-current-directory-to-the-script-directory-or-the-current-directory-if-run-in-a-session/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://powertoe.wordpress.com/2012/11/02/powerbits-9-set-the-current-directory-to-the-script-directory-or-the-current-directory-if-run-in-a-session/ | |
$currdir = '' | |
if ($MyInvocation.MyCommand.Path) { | |
$currdir = Split-Path $MyInvocation.MyCommand.Path | |
} else { | |
$currdir = $pwd -replace '^\S+::','' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment