In my directory I have a file called "t1.ps1" and a second file called "t1 - something.ps1".
Both of them run fine when run fine, when executed via right click run with PowerShell or when executed directly in PowerShell, but when executed via double click or cmd it seems to always execute the first script.
For me it seems like the dash is the problem, but I was kinda surprised that windows did not just throw an error or just did nothing, but instead executed a different script.
Maybe this is a well known phenomena or i just have some jank settings, that made this happen, but I was kinda surprised about it.
CodePudding user response:
By default,
.ps1
files are NOT executed when you double-click them in File Explorer / on the Desktop - instead, they're opened for editing.The fact that they are executed for you implies that you modified the default configuration:
However, the fact that double-clicking
t1 - something.ps1
executest1.ps1
instead implies that your configuration is flawed:Specifically, it suggests that the file-name argument in the underlying
powershell.exe
command used for invocation lacks (effective) enclosing"..."
quoting - as would happen if you had used File Explorer to interactively associate.ps1
files withpowershell.exe
.See this answer for more information and a fix.