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 - associate .ps1 filetype with powershell

Reply
 
Old 07-05-2007   #1 (permalink)
Robert Ludig


 
 

associate .ps1 filetype with powershell

What would be the best way to associate the .ps1 filetype with
powershell? So that doubleclicking a .ps1 will result in execution of
the script? Generally I would like use .ps1 as a replacement for .bat
on my local dev machine.


My System SpecsSystem Spec
Old 07-05-2007   #2 (permalink)
Roman Kuzmin


 
 

Re: associate .ps1 filetype with powershell

Let me describe my way of doing this for scripts that do not require
investigation of console output.

I create this association by PowerShell (well, FType) command (unfortunately
it will not work if a path contains '):

## Associate .ps1 files with PowerShell.exe
cmd /c @"
FType Microsoft.PowerShellScript.1=$pshome\powershell.exe -noexit . "'%1'"
%* ; exit
"@

Advantages:
*) if a script succeeds its console window is closed, so that I do not have
to do it manually.
*) if a script fails its console is not closed because of -noexit and not
yet executed final 'exit' statement. Now I can:
- read the output (if any) and error messages;
- investigate current variables, environment and etc (note: the script was
dot-sourced);
- fix some (outside) problems and re-run the script with full set of
original parameters simply by 'r' command which is a default alias of
Invoke-History (or by 'r 1' command if I ran some other commands)

I found this technique very useful for many tasks.

--
Thanks,
Roman Kuzmin
PowerShellFar and FarNET: http://code.google.com/p/farnet/


"Robert Ludig" <schwertfischtrombose@gmx.de> wrote in message
news:1183638063.106052.164580@k79g2000hse.googlegroups.com...
> What would be the best way to associate the .ps1 filetype with
> powershell? So that doubleclicking a .ps1 will result in execution of
> the script? Generally I would like use .ps1 as a replacement for .bat
> on my local dev machine.
>



My System SpecsSystem Spec
Old 07-05-2007   #3 (permalink)
Robert Ludig


 
 

Re: associate .ps1 filetype with powershell

Sorry, how where do I put that configuration string you mentioned?

On 5 Jul., 14:52, "Roman Kuzmin" <z...@z.z> wrote:
> Let me describe my way of doing this for scripts that do not require
> investigation of console output.
>
> I create this association by PowerShell (well, FType) command (unfortunately
> it will not work if a path contains '):
>
> ## Associate .ps1 files with PowerShell.exe
> cmd /c @"
> FType Microsoft.PowerShellScript.1=$pshome\powershell.exe -noexit . "'%1'"
> %* ; exit
> "@
>
> Advantages:
> *) if a script succeeds its console window is closed, so that I do not have
> to do it manually.
> *) if a script fails its console is not closed because of -noexit and not
> yet executed final 'exit' statement. Now I can:
> - read the output (if any) and error messages;
> - investigate current variables, environment and etc (note: the script was
> dot-sourced);
> - fix some (outside) problems and re-run the script with full set of
> original parameters simply by 'r' command which is a default alias of
> Invoke-History (or by 'r 1' command if I ran some other commands)
>
> I found this technique very useful for many tasks.
>
> --
> Thanks,
> Roman Kuzmin
> PowerShellFar and FarNET:http://code.google.com/p/farnet/
>
> "Robert Ludig" <schwertfischtromb...@gmx.de> wrote in message
>
> news:1183638063.106052.164580@k79g2000hse.googlegroups.com...
>
>
>
> > What would be the best way to associate the .ps1 filetype with
> > powershell? So that doubleclicking a .ps1 will result in execution of
> > the script? Generally I would like use .ps1 as a replacement for .bat
> > on my local dev machine.- Zitierten Text ausblenden -

>
> - Zitierten Text anzeigen -



My System SpecsSystem Spec
Old 07-05-2007   #4 (permalink)
Roman Kuzmin


 
 

Re: associate .ps1 filetype with powershell

> Sorry, how where do I put that configuration string you mentioned?

Put it into the file, say, Install-Association.ps1 and run it once.
Mind unwanted line break on wrapping in the text.

--
Thanks,
Roman Kuzmin
PowerShellFar and FarNET: http://code.google.com/p/farnet/


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How can I remove ALL the programs a filetype opens with?, Make a filetype not to open General Discussion
How can I remove ALL the programs a filetype opens with?, Make a filetype not to open Vista General
How do I change filetype icons? Vista General
Changing Icon FileType Vista General
filetype Vista General


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