How can I associate a file type with a powershell script?

后端 未结 5 1154
名媛妹妹
名媛妹妹 2021-02-14 10:10

I have a very powershell script that works perfectly and does:

Param(
  [string]$fileName
) 

echo \"Woo I opened $fileName\"

When I run it on

5条回答
  •  醉酒成梦
    2021-02-14 10:40

    Here is a concrete answer tested under Windows 7 (but should work under 10 too). Open an administrative command shell and execute the following two lines once:

    > assoc .ps1=Microsoft.PowerShellScript.1
    > ftype Microsoft.PowerShellScript.1=%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -File "%1"
    

    Now PS1-files are executed by PowerShell 1.0 and not opened by Notepad anymore when double-clicked in the Explorer.

提交回复
热议问题