Home > Blockchain >  PowerShell asks "How do you want to open this file" when executing command
PowerShell asks "How do you want to open this file" when executing command

Time:04-02

After upgrading from to Windows 11 the Select-String cmdlet stopped working and everytime I use it, it tries to "open an unknown file" as in image bellow:

Example of strange Select-String behaviour

I found it out when I tried to run one of my ps scripts from batch file - in Win 10 it worked well, but in Win 11 it doesn't. When I run the code in VSCode, it works correctly, I have no clue why.

Example of VSCode's Select-String correct behaviour

I tried to copy texts from VSCode (in case of different encoding) to a new file and directly to PowerShell terminal, but none of these worked.

I tried also the new Windows 11 terminal and updating PowerShell to the latest version (7.2.2 x64), but nothing worked.

Dis/Enabling the system function of Windows PowerShell 2.0 has no effect in this case as well.

EDIT:
I found out that if I run the command Update-Script (without any parameters) at the beginning of the script, Select-String works as expected (before that the cmdlet seems to not exist at all - Get-Help Select-String didn't find anything, but after using Update-Script it finds appropriate help). Some other commands does the same (eg. Trace-Command). See the output:

PS C:\> Get-Command Select-String
CommandType  Name           Version    Source
-----------  ----           -------    ------
Application  Select-String  0.0.0.0    C:\WINDOWS\system32\Select-String

PS C:\> Update-Script
PS C:\> Get-Command Select-String

CommandType  Name           Version    Source
-----------  ----           -------    ------
Cmdlet       Select-String  3.1.0.0    Microsoft.PowerShell.Utility

The Trace-Command "makes" the Select-String works properly as the Update-Script does and gives this output:

DEBUG: CommandDiscovery Information: 0 : Looking up command: Select-String
DEBUG: CommandDiscovery Information: 0 : Cmdlet found: Select-String  Microsoft.PowerShell.Commands.SelectStringCommand 
hello everybody!

Why do I have to do that (call the Update-Script), when Select-String should work without it?

CodePudding user response:

Well, there are a lot of discussions (not really solved) about powershell "how do you want to open this file", but finally, this was the problem of mine:

https://serverfault.com/questions/1038546/powershell-start-job-returns-a-how-do-you-want-to-open-this-file-with-some-cm

Solution:

Delete file c:\Windows\System32\Select-string (0 bytes, no file extension). I have no idea how it got there...

  • Related