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. #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

  3. #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

  4. #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

  5. #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

  6. #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

  7. #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

  8. #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

  9. #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
Hi, I have a HOME environment variable set which I would like to delete. Now the problem is I can't find it anywhere. The usual way like 'computer...
General Discussion
how to set system's environment variable permanently
How to add a Windows envirenment var permanently with PowerShell? The PowerShell Cookbook by Lee Holmes says this: $oldPersonalPath =...
PowerShell
environment variable not seen
I maintain software written some time back with the discontinued IBM VisualAge C++ system. I recently added a laptop with Vista x64 and I am...
Software
vista's environment variable for the temp folder
Does anyone know why Microsoft decided to put the users temp folder under the users profile. Is it for security reasons, so if someone else logs on...
General Discussion
Path Environment Variable - Vista 64-bit
Can someone else confirm this problem: In 'Environment Variables' under 'System Properties' create a User Path string that will force the...
Vista General
how to set environment variable where name is not a-z nor A-Z
i need to set source.dir environment variable in my scripts, if I use $env:source.dir=c:\source i got error like "Property 'dir' cannot be...
PowerShell
how to set environment variable where name is not a-z nor A-Z
i need to set source.dir environment variable in my scripts, if I use $env:source.dir=c:\source i got error like "Property 'dir' cannot be...
PowerShell