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 - PATHEXT environment variable and PS1 scripts

Reply
 
Old 06-27-2007   #1 (permalink)
ThuyLee


 
 

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
Old 06-27-2007   #2 (permalink)
Roman Kuzmin


 
 

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
Old 06-27-2007   #3 (permalink)
Marco Shaw


 
 

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
Old 06-27-2007   #4 (permalink)
ThuyLee


 
 

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
Old 06-28-2007   #5 (permalink)
Roman Kuzmin


 
 

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
Old 06-28-2007   #6 (permalink)
Roman Kuzmin


 
 

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
Old 06-28-2007   #7 (permalink)
ThuyLee


 
 

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
Old 06-28-2007   #8 (permalink)
Roman Kuzmin


 
 

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
Old 06-28-2007   #9 (permalink)
ThuyLee


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
how to set system's environment variable permanently PowerShell
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


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