Why do Get-Content and Import-CSV Open Notepad and Excel?

Has anyone seen this before?

Whenever my scripts call Get-Content, my windows 10 machine opens notepad instead of processing the script. If I call Import-CSV, the environment tries to open Excel.

example:

$mycontent = Get-Content .\mytextfile.txt

or

$mycontent = Import-CSV .\mycsvfile.csv

When run from a script these open the apps instead of processing. This doesn’t happen when I enter the commands directly at the command line, but only when I try to run a script containing the commands, even if the script is launched from the command line.

The behavior just started last week, on this machine.

I’m running PowerShell ISE, PowerShell 5.1 (and 7.x) on Windows 10.

Thanks

Hi, welcome to the forum :wave:

It sounds like it’s ignoring everything before the filename, and just executing the path to the file, which would open the associated program.

I would try putting the line into Notepad, saving as a .ps1 file, and testing that and see if it happens in there too.

My guess is this is some sort of encoding problem. Either with how the ISE is saving the file, or with how the console is interpreting it.