Solved Run PS1 files (double click) on Windows 11


ChristianL

Member
Local time
4:01 AM
Posts
2
Visit site
OS
Windows 11 Education
Hello,
On Windows 10 I was able to modify the file association by using the following command :

Set-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command" -Name '(Default)' -Value '"C:\Program Files\PowerShell\7\pwsh.exe" -noLogo -ExecutionPolicy bypass -file "%1"'

This command no longer works on Windows 11 because the registry location does not exist. I need a way to make PS scripts to run with a double click and the solution must be in a form of a command , No GUI solutions please.

Thanks
 
Windows Build/Version
21H2

My Computer

System One

  • OS
    Windows 11 Education
    Computer type
    Laptop
    Manufacturer/Model
    Dell
    CPU
    Intel i9-10885H 2.4Ghz
    Motherboard
    Dell
    Memory
    32 GB
    Graphics Card(s)
    GTX 1650 TI
    Monitor(s) Displays
    2
    Screen Resolution
    3840x2400
    Hard Drives
    SSD - 1Tb
    Browser
    Edge
    Antivirus
    Sophos
Example. Running PS_ise.
Any .ps1 file -> Properties: Change PS_ise

# .ps1
If (!(Test-Path "HKCR:\PS_ise.ps1\DefaultIcon")) {
New-Item -Path "HKCR:\PS_ise.ps1\DefaultIcon" -Force
}
Set-ItemProperty -Path "HKCR:\PS_ise.ps1\DefaultIcon" -Name "(default)" -Type ExpandString -Value "$ExtLibraryIcons,-12" -Force
Set-ItemProperty -Path "HKCR:\.ps1" -Name "(default)" -Type String -Value "PS_ise.ps1" -Force
Set-ItemProperty -Path "HKCR:\PS_ise.ps1" -Name "(default)" -Type String -Value "File .ps1" -Force
If (!(Test-Path "HKCR:\PS_ise.ps1\Shell\Open\Command")) {
New-Item -Path "HKCR:\PS_ise.ps1\Shell\Open\Command" -Force
}
Set-ItemProperty -Path "HKCR:\PS_ise.ps1\Shell\Open" -Name "FriendlyAppName" -Type String -Value "PS_ise" -Force
Set-ItemProperty -Path "HKCR:\PS_ise.ps1\Shell\Open\Command" -Name "(default)" -Type String -Value '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe" "%1"'-Force
 

My Computer

System One

  • OS
    Microsoft Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    ASUS TUF Dash F15 FX516PM_FX516PM
    CPU
    Intel Core i7-11370H
    Motherboard
    ASUS FX516PM
    Memory
    Micron 4ATF1G64HZ-3G2E2/8G + Patriot PSD416G320081S
    Graphics Card(s)
    NVIDIA GeForce RTX 3060 Laptop
    Sound Card
    Edifier 800BT Plus
    Monitor(s) Displays
    LM156LF-2F03
    Screen Resolution
    1920 x 1080
    Hard Drives
    1. PCIe Gen 4 KINGSTON SNV2S1000G
    2. PCIe Gen 3 SK Hynix HFM512GD3JX013N
    PSU
    200W
    Mouse
    Corsair KATAR PRO XT
    Internet Speed
    70 Mbps
    Browser
    Firefox
    Antivirus
    Microsoft Defender Antivirus
Thanks abactuon !! - I modified your script and everything is working as needed
 

My Computer

System One

  • OS
    Windows 11 Education
    Computer type
    Laptop
    Manufacturer/Model
    Dell
    CPU
    Intel i9-10885H 2.4Ghz
    Motherboard
    Dell
    Memory
    32 GB
    Graphics Card(s)
    GTX 1650 TI
    Monitor(s) Displays
    2
    Screen Resolution
    3840x2400
    Hard Drives
    SSD - 1Tb
    Browser
    Edge
    Antivirus
    Sophos
Hi - sorry to necro a thread, but running into this with machines that need to run by default from group policy. We've tried every registry entry we can think of and are going to test the script above. Nothing works on Windows 11 except manually setting it in control panel, which we can't do. These machines have to run a powershell created by another application dedicated to the user who badged in to function correctly. Has anyone else weaponized this for widescale deployment?
 

My Computer

System One

  • OS
    Windows 11 Insider Developer Preview
Download SetUserFTA, and create a new FTA (file type association). Double-clicking on *.ps1 will auto-run from Explorer.

Code:
ftype Microsoft.PowerShellScript.1="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -ExecutionPolicy Bypass -f "%1"
SetUserFTA.exe .ps1 Microsoft.PowerShellScript.1

If you prefer PS 7:
Code:
ftype Microsoft.PowerShellScript.1="C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -ExecutionPolicy Bypass -f "%1"
 

My Computer

System One

  • OS
    Windows 7

Latest Support Threads

Latest Tutorials

Back
Top Bottom