• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

PATHEXT environment variable and PS1 scripts

T

ThuyLee

#1
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 Computer

R

Roman Kuzmin

#2
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 Computer

M

Marco Shaw

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

R

Roman Kuzmin

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

R

Roman Kuzmin

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

T

ThuyLee

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

R

Roman Kuzmin

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

T

ThuyLee

#9
> 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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)