1.    2 Weeks Ago #1
    Join Date : Nov 2017
    Posts : 3
    Windows 10 Pro

    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.    2 Weeks Ago #2
    Join Date : Jan 2015
    UK, Midlands
    Posts : 10,953
    Win 10 Pro (1703)

    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.    2 Weeks Ago #3
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,947
    Windows 10 Pro
      My ComputerSystem Spec
  4.    1 Week Ago #4
    Join Date : Nov 2017
    Posts : 3
    Windows 10 Pro
    Thread Starter

    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.    1 Week Ago #5
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,947
    Windows 10 Pro

    Quote Originally Posted by WinTenUsr 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.    1 Week Ago #6
    Join Date : Nov 2017
    Posts : 3
    Windows 10 Pro
    Thread Starter

    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

 


Similar Threads
Thread Forum
Solved Zoom Player File type associations
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...
Software and Apps
File type associations not launching the program in the list
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...
Software and Apps
Unassociated file associations only running programs as administrator
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...
Software and Apps
File associations don't work
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...
Software and Apps
How to stop updates from overwriting file & icon associations?
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...
General Support
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 16:42.
Find Us
Twitter Facebook Google+ Ten Forums iOS App Ten Forums Android App



Windows 10 Forums