Download remote file into memory via pure batch


In my batch script, I am trying to download and execute a powershell script remotely. Here is the url:

I want to download the file into memory (without touching disk), for several reasons:

  1. It bypasses AV detection
  2. It bypasses Powershell executionpolicy, so there’s no need for the powershell -nop -ep bypass that causes AV detection
  3. Won’t throw unneccessary syntax errors
  4. You can directly use functions defined inside the .ps1 script

Obviously i can use certutil:

but I don’t want the file to hit disk, which can cause AV detection.
The same thing can be done with easily using other languages, like PowerShell:


I know batch isn’t the best language to do this, but is it possible? (I want pure batch)


Download and execute without a temporary file

Example test.bat

Building the code

As said in Force batch file to load to RAM before running you can cache a single command block.

There are some limitations:

  • It’s running in cmd (not batch) context,
    variable expansion is a bit different.
  • Labels can’t be used

With this technique you can use the normal batch macro style.


Download remote file into memory via pure batch by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply