Please feel free to provide feedback or file bugs here.

Bug: Ps1 script file with extra extension gets deleted when called from CMD

When calling PowerShell from CMD and specifying a script file that contains an extra "extension" (extra dot) in the base name, the script is not run but the file is mysteriously deleted:

Example (run in CMD):

powershell -file c:\temp\script.txt.ps1

The same issue when called like this:

powershell -command "& c:\temp\script.txt.ps1"

This has been reproduced by me and others on different machines with different paths.

The same issue exists when called from inside PowerShell like this:

. "powershell.exe" -file c:\temp\script.txt.ps1
Start-Process "powershell" -Arg "-file, "c:\temp\script.txt.ps1"

Note that these will work just fine:

powershell -command "& 'c:\temp\script.txt.ps1'"
powershell -command ";& c:\temp\script.txt.ps1"
powershell -file "c:\temp\script.ps1.ps1"

Could this be an optimization bug?

1 vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

Marsze shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Reinhard P. commented  ·   ·  Flag as inappropriate

    I've only test your first example, but can reproduce this behaviour on my System. It seems not to be a bug in Powershell, it's a feature of your antivir program. My Kaspersky blocks Powershell and delete the script file.

Feedback and Knowledge Base