I have a very powershell script that works perfectly and does:
Param(
[string]$fileName
)
echo "Woo I opened $fileName"
When I run it on the command line, it works:
my-script.ps1 .\somefile
Returns:
Woo I opened somefile
I would like to associate my-script.ps1
with a particular file type. I am attempting to do this via 'Open With' However:
How can I associate a file type with a Powershell script?
Use the proper tools for the job:
cmd /c assoc .fob=foobarfile
cmd /c ftype foobarfile=powershell.exe -File `"C:\path\to\your.ps1`" `"%1`"
Note that both assoc
and ftype
are CMD-builtins, so you need to run them via cmd /c
from PowerShell.
For files without extension use this association:
cmd /c assoc .=foobarfile
I don't think you can do it through Windows UI.
The goal here is to associate a type with powershell.exe, arguments to which will be
To do this
Regedit.exe
. //disclaimer: you are editing Windows registry. Here be tigers.
.<extension>
, e.g. if you want to associate *.zbs - create a key .zbs
zbsfile
-- this is a reference linking your extension to a filetype.zbsfile
- this is your filetypezbsfile
shell
open
command
command
, set (default) value to e.g.powershell.exe -File "C:\path\to your\file.ps1" "%1"
That should work.
EDIT:
or (crazy idea), create a bat file doing just powershell.exe -File "C:\path\to your\file.ps1" "%%1"
and select it in Windows UI...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With