I don't have enough rep to comment, so I am going to go on the information provided. Apologies in advance if you already tried some of these steps.
Preface
Your code ran fine for me in PowerShell 7 and PowerShell 5 on Windows 10. Most of the code also ran fine in PowerShell 7 on Ubuntu 22.04 (the -ComObject flag doesn't seem to exist in PowerShell 7 on Linux, or at least I couldn't find it, I didn't see any mention of this fact in the docs though).
I Mostly program on and use Linux these days and I haven't written any PowerShell scripts for Windows in at least a year.
Troubleshooting
Stupid Questions First
- Can you verify that the directory you are trying to access with the script exists and that there aren't any typos in the path your code is using?
- If it does exist, are there any files in the directory the script is accessing, or is it currently empty? If it is empty, this script will run and quit in the blink of an eye so you just might not be seeing it.
- Did you try turning it off and back on again :)
Explorer.exe Default Application for PowerShell is Notepad
By default Windows has notepad.exe set to be the native application for opening PowerShell scripts when double-clicked in explorer.exe. This is intended as a semi-security feature and prevents accidentally executing PowerShell scripts that you didn't want to (for instance if you have a script that deletes files). If you change that default application to be the native PowerShell instance, that should allow you to run the script instead of launching notepad when you double click.
Running in a Non-ISE Terminal
If you already set the default application to PowerShell and it still isn't running, try opening a normal (non-ISE) PowerShell session, navigating to the folder the script is in and running it with .\<script_name.ps1>
. If there is an error or issue preventing your script from running, this should (hopefully) let you know what it is. It's possible that the script is actually launching when you double click it, but that it's immediately closing due to an error such as lacking permissions.
Running as an Admin
You could also try running the terminal session as an Administrator to see if perhaps you are just running into permissions issues. Just be aware that any child process spawned by your PowerShell script will inherit the Admin privileges. If you're the only one using the PC and are just opening text files this probably isn't that big of an issue, but if you're opening arbitrary demo programs from the internet....
To launch PowerShell (or CMD) as an admin, just right click the start button in the task bar and select the option "Windows PowerShell (Admin)".
Using a CMD .bat File to Launch the Script
Worst comes to worst, you can always create a batch file that launches the PowerShell script and which also bypasses the execution policy for good measure. See this question for a detailed response, but the short version is to put the following in the batch file powershell.exe -ExecutionPolicy bypass -file "<script_name.ps1>"
Further Reading
It looks like this question might be related. It goes over issues getting a PowerShell script to run with double click in explorer.exe.
Notes
You can use a shortcut in place of the batch file and just put the command directly into the shortcut. I personally prefer the batch file as they're easier to edit (imo), but they're functionally identical so there's no real reason to use one over the other that I can think of offhand.
Nowadays the recommended editing environment for PowerShell scripts is VSCode with the PowerShell Extension installed. See here for some more information. My understanding is that Powershell_ISE is essentially in maintenance mode and won't be receiving any more updates (other than security patches). Microsoft's documentation has the following to say:
The PowerShell ISE is no longer in active feature development. As a shipping component of Windows, it continues to be officially supported for security and high-priority servicing fixes. We currently have no plans to remove the ISE from Windows.
There is no support for the ISE in PowerShell v6 and beyond. Users looking for replacement for the ISE should use Visual Studio Code with the PowerShell Extension.
I personally do still like the ISE for some things, but VSCode (or VSCodium) is nevertheless the modern supported solution to the problem.
If you want an application you easily launch by double clicking and which you use on multiple computers, PowerShell might not be the easiest for this due to how much effort MS puts into making it difficult to launch PS scripts from Explorer. That isn't to say you shouldn't use PowerShell, particularly if it meets other design requirements (such as being available natively on all Windows PC's), just that you will have to jump through a few more hoops than you might have had to with Python, Perl, or Lua (but none of these are natively available on Windows and do have some other challenges of their own).
If none of the above helps, it might be useful to provide details such as what happens when you double click on the script, what the directory structure looks like, letting us know what the default version of PowerShell on your system is see here if you don't know how to find that, and any other information that you can provide to help. You also mentioned that you looked at 10 or so other threads, and that they were either too specific or not relevant; while certainly not necessary it might be beneficial to list some of those threads with a little information on how they failed to help so that way we can avoid re-treading that ground on accident.
I hope that this was helpful, best of luck getting this issue resolved!