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.

  • You could write a wrapper script, that would list all your personal scripts and let you pick one to run? – Xen2050 Jan 18 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 Jan 18 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 Jan 18 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 Jan 18 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 Jan 18 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.