Windows Vista Forums

PATHEXT environment variable and PS1 scripts

  1. #1


    ThuyLee Guest

    PATHEXT environment variable and PS1 scripts

    Hello:

    The PATHEXT environment variable in PowerShell does not include .PS1 in the
    list, yet you can still run PowerShell scripts without typing the .PS1
    extension on script files. I assume PowerShell ignores PATHEXT?

    Is there a way to force the user to enter the full name of a PowerShell
    script, including the extension, when running a script?

    The benefit is that the user will know they are running a script when they
    think they are running an EXE (e.g., a ping.ps1 script earlier in the PATH
    than ping.exe).

    Btw, will the extension be changed to .PS2 with the next version of
    PowerShell?

    Thx!






      My System SpecsSystem Spec

  2.   


  3. #2


    Roman Kuzmin Guest

    Re: PATHEXT environment variable and PS1 scripts

    My preference is not to use .ps1 at all. Due to various reasons many of my
    scripts were converted into functions\filters and many functions\filters
    were converted into scripts. This was relatively painless because I never
    use .ps1.

    --
    Thanks,
    Roman Kuzmin

    "ThuyLee" <tlee3@unlv.edu> wrote in message
    news:uIB8rLOuHHA.4476@TK2MSFTNGP03.phx.gbl...
    > Hello:
    >
    > The PATHEXT environment variable in PowerShell does not include .PS1 in
    > the list, yet you can still run PowerShell scripts without typing the .PS1
    > extension on script files. I assume PowerShell ignores PATHEXT?
    >
    > Is there a way to force the user to enter the full name of a PowerShell
    > script, including the extension, when running a script?
    >
    > The benefit is that the user will know they are running a script when they
    > think they are running an EXE (e.g., a ping.ps1 script earlier in the PATH
    > than ping.exe).
    >
    > Btw, will the extension be changed to .PS2 with the next version of
    > PowerShell?
    >
    > Thx!




      My System SpecsSystem Spec

  4. #3


    Marco Shaw Guest

    Re: PATHEXT environment variable and PS1 scripts

    ThuyLee wrote:
    > Hello:
    >
    > The PATHEXT environment variable in PowerShell does not include .PS1 in
    > the list, yet you can still run PowerShell scripts without typing the
    > .PS1 extension on script files. I assume PowerShell ignores PATHEXT?
    >
    > Is there a way to force the user to enter the full name of a PowerShell
    > script, including the extension, when running a script?
    >
    > The benefit is that the user will know they are running a script when
    > they think they are running an EXE (e.g., a ping.ps1 script earlier in
    > the PATH than ping.exe).
    >
    > Btw, will the extension be changed to .PS2 with the next version of
    > PowerShell?
    >
    > Thx!


    Well, you could consider adding a library or header to each script to
    determine if it was called properly, if not, exit, or at least exit with
    a message that looks like a real PowerShell generated error.

      My System SpecsSystem Spec

  5. #4


    ThuyLee Guest

    Re: PATHEXT environment variable and PS1 scripts

    > My preference is not to use .ps1 at all.

    Interesting, so you use a different extension, or no extension at all?




      My System SpecsSystem Spec

  6. #5


    Roman Kuzmin Guest

    Re: PATHEXT environment variable and PS1 scripts

    I use no extension at all. BTW, different extensions are not allowed for PS
    scripts.

    --
    Thanks,
    Roman Kuzmin


    "ThuyLee" <tlee3@unlv.edu> wrote in message
    news:uf%23lSKRuHHA.4788@TK2MSFTNGP05.phx.gbl...
    >> My preference is not to use .ps1 at all.

    >
    > Interesting, so you use a different extension, or no extension at all?




      My System SpecsSystem Spec

  7. #6


    Roman Kuzmin Guest

    Re: PATHEXT environment variable and PS1 scripts

    I forgot to mention ability to use an alias for any command at any moment
    (optionally taking scope into account). I believe aliases like
    'do-something.ps1' are possible, too, but they look confusing. So, again,
    using extension '.ps1' in the code looks less flexible to me.

    --
    Thanks,
    Roman Kuzmin



      My System SpecsSystem Spec

  8. #7


    ThuyLee Guest

    Re: PATHEXT environment variable and PS1 scripts

    >I use no extension at all.

    On 32-bit Vista, I get a pop-up dialog box asking which program I want to
    use to run the script if I remove the ".ps1" extension from the script,
    e.g., while in the shell in the folder with the script, ".\scriptname"
    doesn't execute the script, it pops up the OpenWith dialog box. Does yours
    work differently? (Sorry for all the follow-up questions.)



      My System SpecsSystem Spec

  9. #8


    Roman Kuzmin Guest

    Re: PATHEXT environment variable and PS1 scripts

    Sorry if I did not understand your problem correctly (and BTW, I have no
    Vista experience yet). Are you talking about running PS scripts by
    PowerShell.exe 'from Windows' or invoking scripts from already running
    PowerShell session? I am talking about the latter case.


    --
    Thanks,
    Roman Kuzmin

    "ThuyLee" <tlee3@unlv.edu> wrote in message
    news:%23yH%23cxYuHHA.4952@TK2MSFTNGP04.phx.gbl...
    > >I use no extension at all.

    >
    > On 32-bit Vista, I get a pop-up dialog box asking which program I want to
    > use to run the script if I remove the ".ps1" extension from the script,
    > e.g., while in the shell in the folder with the script, ".\scriptname"
    > doesn't execute the script, it pops up the OpenWith dialog box. Does
    > yours work differently? (Sorry for all the follow-up questions.)
    >
    >




      My System SpecsSystem Spec

  10. #9


    ThuyLee Guest

    Re: PATHEXT environment variable and PS1 scripts

    > Are you talking about running PS scripts by PowerShell.exe 'from Windows'
    > or invoking scripts from already running PowerShell session? I am talking
    > about the latter case.


    Having an interactive PowerShell shell open (not CMD), then executing
    ".\scriptname" with no extension on the scriptname and not prefacing with
    "powershell.exe ..." first.



      My System SpecsSystem Spec


PATHEXT environment variable and PS1 scripts

Similar Threads
Thread Forum
can't delete HOME environment variable General Discussion
environment variable not seen Software
Path Environment Variable - Vista 64-bit Vista General
how to set environment variable where name is not a-z nor A-Z PowerShell
how to set environment variable where name is not a-z nor A-Z PowerShell