0

If I have a PowerShell script named myscript.ps1 and it sits in the PATH, I'd like to be able to press Windows + r, type "myscript", and press enter. Currently it requires me to type myscript.ps1, and it runs fine.

I've found a few answers that suggested ftype, assoc, and the PATHEXT environment variable, but that only affects scripts run from command prompt or PowerShell, not from explore.exe's Run prompt.

I assume there's some registry setting, but I don't know what to search for, as fileext has hundreds of entries. I also searched for .bat since batch files work automatically, but I haven't found anything obvious.

I thought I'd found it under under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\KindMap by adding a .ps1 value and setting it to program as .bat, .cmd, .com, and .exe all are set that way, but no dice (even after restarting my computer).

I also noticed that .bat, .cmd, .exe, .lnk, and .msi each had an HKCR\<app-handler-id>\shellex\PropertySheetHandlers\ShimLayer Property Page set to {513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}, but adding that to HKCR\Microsoft.Powershell.1 didn't worth either.

7
  • You could write a wrapper script, that would list all your personal scripts and let you pick one to run?
    – Xen2050
    Commented Jan 18, 2019 at 0:18
  • I considered that, and I might do it, but I still want my question answered. I'm curious how Windows works.
    – dx_over_dt
    Commented Jan 18, 2019 at 0:19
  • I guess you need the full name to run things. If you were in a terminal, you could try pressing TAB to auto-complete many things (programs, files, directories...)
    – Xen2050
    Commented Jan 18, 2019 at 1:06
  • Certain file extensions aren't required though: .bat, .exe, .cmd, etc. I assume those aren't hard-coded into the OS, so there should be a way to change them and add .ps1.
    – dx_over_dt
    Commented Jan 18, 2019 at 1:08
  • 1
    @EricW. Yeah, I just don't like workarounds in general. Plus, it requires a batch file for every script unless you want to use the ps1 script as an argument to the batch script; in that case it ends up saving you a total of 2 characters assuming the batch's file name is only 1. It turns out .lnk (shortcut files) also do not require an extension, so I think I'm going to go that route for my one script.
    – dx_over_dt
    Commented Jan 18, 2019 at 21:11

1 Answer 1

0

The best way I found for me was here to use the following in a .bat:

start wt your-command
exit

I'm using Windows Terminal since I like the handling far more than the regular powershell, but this also works with powershell instead of wt. The exit command is used to close the window in case I'm running it from an open cmd shell.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .