Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to determine a script location?

965 views
Skip to first unread message

Jeff Jarrell

unread,
Jun 1, 2007, 11:18:36 AM6/1/07
to
Inside a basic .PS1 script how do I determine the location of the PS1. What
i am doing is I want to locate a config file which will be located in the
same dir as the script.

Thanks,
jeff


Alex Harden

unread,
Jun 1, 2007, 1:34:24 PM6/1/07
to

$(pwd).path

-a

RichS

unread,
Jun 1, 2007, 1:45:02 PM6/1/07
to
Could also use

$myinvocation.mycommand.path

see
http://msgoodies.blogspot.com/2007/04/powershell-writing-debug-output.html
for more information
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

Brandon Shell

unread,
Jun 1, 2007, 2:38:11 PM6/1/07
to
I would be careful using $pwd as it only tells you the current Path which
could be changed.

Using: $myinvocation.mycommand.path (as Rich Suggest) is much better IMO.

"Alex Harden" <aha...@gmail.com> wrote in message
news:1180719264.3...@q66g2000hsg.googlegroups.com...

Clint Bergman

unread,
Jun 1, 2007, 3:00:34 PM6/1/07
to
If it will be in a script, you can also get the path to the script's location with:

split-path $myinvocation.scriptname

~Clint

"Alex Harden" <aha...@gmail.com> wrote in message news:1180719264.3...@q66g2000hsg.googlegroups.com...

William Stacey [C# MVP]

unread,
Jun 1, 2007, 3:30:50 PM6/1/07
to
While on the subject, I noticed things like UserAppDataPath are not relevant
inside a cmdlet.
Console.WriteLine("AppDir:"+Application.UserAppDataPath);

AppDir:C:\Documents and Settings\Administrator\Application Data\Microsoft
Corporation\Microsoftr Windowsr Operating System\6.0.5430.0

I realize this is because it is probably using the Powershell.exe info as it
is the exe. However, it would seem like this should be fixed somehow to
allow cmdlets to use this info consistent with other applications.
--
William Stacey [C# MVP]
PowerLocker, PowerPad
www.powerlocker.com


"Jeff Jarrell" <jjarr...@yahoo.com> wrote in message
news:%23g%23IzBGp...@TK2MSFTNGP03.phx.gbl...

Jeff Jarrell

unread,
Jun 1, 2007, 3:56:59 PM6/1/07
to
this is what I was looking for. Thanks.

"RichS" <Ri...@discussions.microsoft.com> wrote in message
news:2170ECCA-1467-48BC...@microsoft.com...

0 new messages