Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

script location and $pwd

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 12-10-2006   #1 (permalink)
Doug
Guest


 

script location and $pwd

I have a script which loads a .Net dll like this

[reflection.assembly]::loadfrom("$pwd\lvl1\lvl2\bin\debug\target.dll")

Works great when I am in the same directory as the script.

When I Set-Location to the directory below and execute this script file

...\test.ps1

The loadfrom fails.

How can I guard against this?
The $MyInvocation.MyCommand.Defintion is empty
(works great if the script is in a directroy that is in my path though)

Thanks

My System SpecsSystem Spec
Old 12-10-2006   #2 (permalink)
RichS
Guest


 

RE: script location and $pwd

I think you need to define the fullpath to the dll if you are not in the same
directory as the script
--
Richard Siddaway

Please note that all scripts are supplied "as is" and with no warranty


"Doug" wrote:

> I have a script which loads a .Net dll like this
>
> [reflection.assembly]::loadfrom("$pwd\lvl1\lvl2\bin\debug\target.dll")
>
> Works great when I am in the same directory as the script.
>
> When I Set-Location to the directory below and execute this script file
>
> ..\test.ps1
>
> The loadfrom fails.
>
> How can I guard against this?
> The $MyInvocation.MyCommand.Defintion is empty
> (works great if the script is in a directroy that is in my path though)
>
> Thanks

My System SpecsSystem Spec
Old 12-10-2006   #3 (permalink)
Adam Milazzo
Guest


 

Re: script location and $pwd

RichS wrote:
> I think you need to define the fullpath to the dll if you are not in the same
> directory as the script


There should be a way to get the path to the currently-executing script,
though...
My System SpecsSystem Spec
Old 12-10-2006   #4 (permalink)
Doug
Guest


 

Re: script location and $pwd


"Adam Milazzo" wrote:

> RichS wrote:
> > I think you need to define the fullpath to the dll if you are not in the same
> > directory as the script

>
> There should be a way to get the path to the currently-executing script,
> though...
>


Yes, I am looking for that. I shuttle this code from my home machine to my
work machine and would like to not have to update the script each time.
My System SpecsSystem Spec
Old 12-11-2006   #5 (permalink)
RichS
Guest


 

Re: script location and $pwd

Have you seen this article

http://blogs.msdn.com/powershell/arc...-run-from.aspx

$MyInvocation.MyCommand.Path may do what you want


"Doug" wrote:

>
> "Adam Milazzo" wrote:
>
> > RichS wrote:
> > > I think you need to define the fullpath to the dll if you are not in the same
> > > directory as the script

> >
> > There should be a way to get the path to the currently-executing script,
> > though...
> >

>
> Yes, I am looking for that. I shuttle this code from my home machine to my
> work machine and would like to not have to update the script each time.

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Include another script, keep variables in included script? pschmidt PowerShell 32 08-18-2008 01:48 PM
script location? Justin Rich PowerShell 5 05-15-2008 11:55 AM
BUG? Invalid location after Set-Location \\MyMachine Roman Kuzmin PowerShell 3 04-01-2008 11:13 AM
Copying files from the same location as the script greatbarrier86 PowerShell 5 01-13-2008 11:08 AM
how to determine a script location? Jeff Jarrell PowerShell 6 06-01-2007 02:56 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008