![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | script location? i want to find where my script is located... so when i run a command like... c:\>powershell c:\myscripts\thescript.ps1 i'd get back either c:\myscripts or c:\myscripts\thescript.ps1 i found this $myinvocation.mycommand.path but that returns the current location (in this case, c:\) as does $(pwd).path any other suggestions? Thanks Justin |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: script location? Justin Rich wrote:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | RE: script location? Does anyone know whether its possible mark a post as a "sticky"? It would be really nice to start a FAQ. Justin the MyInvocation variable is what you want. The state of this variable depends on the context in which its called which makes it somewhat confusing. Run this script it should help explain as you can see the output is different depending on whether you are at script of function scope. function test { echo "Entering function Test" echo "`$MyInvocation.InvocationName is $($MyInvocation.InvocationName)" echo "`$MyInvocation.MyCommand.name is $($MyInvocation.MyCommand.name)" echo "`$MyInvocation.ScriptName is $($MyInvocation.ScriptName)" echo "`$MyInvocation.MyCommand.path is $($MyInvocation.MyCommand.path)" echo "`$pwd.path $($pwd.path)" echo "Leaving function Test" } echo "Entering MyInvocation Test Scriptblock" echo "`$MyInvocation.InvocationName is $($MyInvocation.InvocationName)" echo "`$MyInvocation.MyCommand.name is $($MyInvocation.MyCommand.name)" echo "`$MyInvocation.ScriptName is $($MyInvocation.ScriptName)" echo "`$MyInvocation.MyCommand.path is $($MyInvocation.MyCommand.path)" echo "`$pwd.path $($pwd.path)" echo "Calling Test" test echo "Leaving MyInvocation Test Scriptblock" "Justin Rich" wrote:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: script location? "Bob Landau" <BobLandau@xxxxxx> wrote in message news:F98C6B35-DDD7-4500-BEF9-417959A614BA@xxxxxx
it would be very useful to web uses. Alternatives (that help with bumping or finding info): I seem to recall that you can vote on posts in the web interface - if you can find that, a few positive votes may help. Personally, when looking for posts on a particular topic I usually just hit the Google Groups advanced search page and scan from there using keywords: http://groups.google.com/advanced_search Not FAQish, but it usually shows me everything relevant. Sadly, that's not useful to people who are new, since part of the problem is learning what you're really searching for. | ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: script location? Yet another alternative that will at least show you what members MyInvocation and MyInvocation.PSBase have is the following - it can be used in a test script file directly as well: function Demo-FunctionMyInvocation{ Write-Output "`n`n+ MyInvocation members:" $MyInvocation | gm Write-Output "`n`n+ MyInvocation PSBase members:" $MyInvocation.PSBase | gm } Demo-FunctionMyInvocation Bob Landau's version is good for real browsing within a specific script; you can't just do something like $MyInvocation | fl * since some of the elements have predefined formatting that chokes with the format-list in place. "Justin Rich" <jrich523@xxxxxx> wrote in message news:uovLN0PtIHA.1240@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||
| Guest | Re: script location? Yeah sorry about the basic post, I was able to find the solution it was just doing weird things at fist, aka, not working... I tried a simple script with it and it kept tossing back the run from location... and after I got the post and tried $myinvocation.invocationname the $myinvocation.mycommand.path started to work... also I at first I was a little stumped because I would run the script from a command prompt and give it the no exit flag.. I had assumed that any objects containing this info would still have it... which apparently isn't the case.. someone needs to make a really good FAQ site.. personally I don't find blogs to be the best solution, not always the easiest way to find the info moving forward.. either way, I appreciate the help. Thanks Justin "Alex K. Angelopoulos" <aka(at)mvps.org> wrote in message news:%23EPY%23QctIHA.4560@xxxxxx
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
![]() |
| 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 |
| 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 |
| script location and $pwd | Doug | PowerShell | 4 | 12-11-2006 02:47 PM |