Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to get the full path for the PS1 itself?

Reply
 
Old 06-20-2009   #1 (permalink)
Carlos Felipe França da Fonseca


 
 

How to get the full path for the PS1 itself?

I would like to know how to get the path for the own script (PS1) using
Powershell.
It's something like this in VBScript:

Set oFS = CreateObject( "Scripting.FileSystemObject" )
ScriptFullPath = oFS.GetParentFolderName( WScript.ScriptFullName)

or

Set oFS = CreateObject( "Scripting.FileSystemObject" )
ScriptFullPath = oFS.GetAbsolutePathName( ".\" )

or

Dim oWS : Set oWS = CreateObject( "WScript.Shell" )
WScript.Echo oWS.CurrentDirectory


Does anyone know something similar using Powershell?

Thanks!

Felipe




My System SpecsSystem Spec
Old 06-20-2009   #2 (permalink)
Alex K. Angelopoulos


 
 

Re: How to get the full path for the PS1 itself?

Use this:

$MyInvocation.MyCommand.Path

To get an idea of what's exposed to you from within a script, you can create
a sample script with this content:
$MyInvocation | fl *
$MyInvocation | gm


"Carlos Felipe França da Fonseca" <carlosfelipefranca@xxxxxx> wrote in
message news:e9bMgBW8JHA.4176@xxxxxx
Quote:

> I would like to know how to get the path for the own script (PS1) using
> Powershell.
> It's something like this in VBScript:
>
> Set oFS = CreateObject( "Scripting.FileSystemObject" )
> ScriptFullPath = oFS.GetParentFolderName( WScript.ScriptFullName)
>
> or
>
> Set oFS = CreateObject( "Scripting.FileSystemObject" )
> ScriptFullPath = oFS.GetAbsolutePathName( ".\" )
>
> or
>
> Dim oWS : Set oWS = CreateObject( "WScript.Shell" )
> WScript.Echo oWS.CurrentDirectory
>
>
> Does anyone know something similar using Powershell?
>
> Thanks!
>
> Felipe
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
What's file's full path and BIOS Vista file management
how to get subdir items with full path name? PowerShell
Full path in the Address bar of Explorer??? Vista installation & setup
BUG/ANNOYANCE: PoSH autocompletes the full path rather than a minimal path PowerShell
full path versus ./filename PowerShell


Vista Forums 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 Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46