Windows 10: How to set file associations in PowerShell so that .ps1 is exec by PS Solved

  1.    03 Nov 2017 #1

    How to set file associations in PowerShell so that .ps1 is exec by PS


    How to set file associations in PowerShell so that a .ps1 Script is executed by PowerShell when double clicked.
    I tried:
    Code:
    cmd /c "ASSOC .ps1=Microsoft.PowerShellScript.1"
    cmd /c "FTYPE Microsoft.PowerShellScript.1=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"" ""%1"""
    No error is shown when executed and the desktop is shortly after refreshed, but unfortunately the .ps1 Script is still not executed by PowerShell.

    I noticed under
    Code:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\
    a
    Code:
    UserChoice
    Folder is created when one manually sets a "Open with" program. This folder contains two important entries:
    Code:
    1.) Hash                REG_SZ               wk2qS8kKVnU <- random value automatically created by Windows 
    2.) ProgId               REG_SZ               Applications\notepad.exe
    But unfortunately one can't manually set a Hash since the Hash value is created automatically by Windows, so the value is kinda secret? -- additionally, the value has a different value each time, despite the a same program name.
      My ComputerSystem Spec

  2.    03 Nov 2017 #2

    How do you do that?
    - have you tried rt clicking your .ps1 file, Open With, and browse to psexec.exe? "Look for another app"?

    Or you could use (freeware)
    Click image for larger version. 

Name:	1.jpg 
Views:	1 
Size:	93.0 KB 
ID:	161959
      My ComputerSystem Spec


  3. Posts : 13,762
    Windows 10 Pro
       03 Nov 2017 #3
      My ComputerSystem Spec

  4.    06 Nov 2017 #4

    Sorry, I forgot to mention that it would be set through a GPO, so no user interaction required. All the user would do is to double click the script and PowerShell would execute it.
      My ComputerSystem Spec


  5. Posts : 13,762
    Windows 10 Pro
       06 Nov 2017 #5

    WinTenUsr said: View Post
    Sorry, I forgot to mention that it would be set through a GPO, so no user interaction required. All the user would do is to double click the script and PowerShell would execute it.
    That can't be done. PowerShell scripts cannot be run by double clicking their icon. The only way is to use shortcut as told in tutorial I linked to.
      My ComputerSystem Spec

  6.    07 Nov 2017 #6

    Thanks, good or not good to know that this can't be done (up to Win7 it was possible AFAIK). I decided to start the PowerShell script through .cmd/.bat, as these are already set to be executed by CMD.
      My ComputerSystem Spec


 

Related Threads
Ever since I've updated to the most recent version of windows all the Video files will no longer asscociate to the various file types withing the Zoom icon library. It seems just to asscociate all to one particular Icon which is the main Zoom player...
This problem has just started on several machines since 8/20/2016. On Windows 10 Pro computers, the program associated with a file type extension will not launch correctly anymore even though the correct program is listed as associated with that...
My issue revolves around encountering read/wright permissions with programs Java-based programs. I currently have installed jdk-8u65-windows-x64 on Windows 10 64-bit. Java is installed on C drive within program files. by Java-based programs reside...
File associations don't work in Software and Apps
OK, so file association for .htm files is set to my text editor. For some reason, though, the text editor won't open when I double-click a .htm file. I get the blue spinning timer thing for a few seconds, then nothing happens. Apart from...
I have been using an application called Default Programs Editor to adjust the default program to open with when a file is opened and also the icon. I have done this once for Windows 10. However, it seems that after the latest update (which seems...
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:06.
Find Us