Flamingo Raises $4.5M Seed Round

Skip to content

Updated: October 2026

A .bat file is a plain text file of Windows commands that runs top to bottom when you open it. Technicians use them for small repeatable jobs: mapping a drive, clearing a cache, copying a log folder. This guide shows how to create and run a .BAT file, how to run it as administrator, and where PowerShell takes over.

What a .BAT File Is

A .bat file, also called a batch file, is a text file that the Windows command interpreter, cmd.exe, reads one line at a time. Each line is a command you could type at a Command Prompt. The file saves the typing and runs the same steps every time.

A .cmd file does the same job in the same interpreter. Microsoft's call command accepts either extension, so the two can call each other.

The detail that trips people up is the language. A .bat file speaks CMD, not PowerShell. In a 2025 r/sysadmin thread, a technician's .bat file stopped at a PowerShell line that worked when pasted into a terminal. The reply: .bat and .cmd files run under CMD, and the terminal defaults to PowerShell.

Our comparison of PowerShell vs CMD covers the language gap in full.

How to Create a .BAT File

You need Notepad and nothing else.

  1. Open Notepad and type one command per line.
  2. Choose File, then Save As.
  3. Set "Save as type" to All files.
  4. Name the file with the .bat extension, for example copylogs.bat, and save it somewhere short such as C:\Scripts.

Here is a starter script:

bat
@echo off
echo Copying logs...
mkdir C:\Temp\Logs 2>nul
xcopy "C:\Logs\App" "C:\Temp\Logs" /E /I /Y
echo Done.
pause

The step people miss is the second one. If "Save as type" stays on Text Documents, Notepad saves copylogs.bat.txt, and a double-click just opens Notepad. Turn on File name extensions in Explorer (View, Show) to see what you really saved.

The Commands Worth Knowing

Batch syntax is small. These do most of the work in a technician's scripts.

CommandWhat it does
@echo offStops each line printing before it runs
echo textPrints a message
set NAME=valueStores a value, read back as %NAME%
if / if errorlevel 1Branches on a test or on the last command's exit code
goto :labelJumps to a label; goto :eof exits the script
call other.batRuns another batch file, then returns
setlocalKeeps variable changes inside this script
%~dp0The drive and folder the script sits in
pauseWaits for a key press
exit /b 1Ends the script with an exit code

Arguments are simple too. Whatever you type after the file name arrives as %1, %2 and so on, and %* holds all of them, so copylogs.bat D:\Archive can pass a destination into the script. Wrap %1 as "%~1" to strip stray quotes and keep paths with spaces intact.

A short example ties them together. It checks that a server answers before mapping a drive:

bat
@echo off
ping -n 1 fileserver >nul
if errorlevel 1 (
  echo Server unreachable. Check the VPN.
  exit /b 1
)
net use Z: \\fileserver\shared

The same net use line, with the Group Policy alternative, is in our guide to map a network drive on Windows 11.

How to Run a .BAT File

There are four common ways, and each has a different use.

  • Double-click. Fastest, but the window closes when the script ends. Add pause as the last line to read the output.
  • From Command Prompt. Open it, cd to the folder, and type the file name, or give the full path in quotes. The window stays open, so errors stay on screen. Use this to debug.
  • From PowerShell. Type .\copylogs.bat. PowerShell will not run a file from the current folder without the .\ prefix.
  • Task Scheduler or a GPO startup script. Runs unattended, which changes whose rights apply.

That last one catches people. In a December 2025 r/sysadmin thread, a batch job that copied files between servers worked as the logged-on user and did nothing as a dedicated service account. Running the script from a command line as that account exposed two permission gaps, on the log file and on the share.

Two safety notes. Right-click and choose Edit to read a .bat file from someone else before you run it, because it runs with your rights. And PowerShell's execution policy only governs PowerShell scripts, so it does not block or allow a .bat file.

How to Run a .BAT File as Administrator

A batch file has no admin setting of its own. It inherits the rights of whatever starts it. Right-click the file and choose Run as administrator; on Windows 11 this can sit under Show more options. If you run the file often, make a shortcut, open Properties, then Advanced, and tick Run as administrator. For a scheduled run, tick Run with highest privileges in Task Scheduler. You can also open Command Prompt as administrator and start the file from there.

The trap is the working folder. An elevated Command Prompt opened from the Start menu lands in C:\Windows\System32, so a script that uses relative paths now looks in the wrong place. Start the script with cd /d "%~dp0" to move into the folder the file lives in.

A guard at the top also saves a confusing failure. net session only succeeds in an elevated window, so it works as a quick check:

bat
net session >nul 2>&1
if errorlevel 1 (
  echo Run this file as administrator.
  pause
  exit /b 1
)

Why a .BAT File Fails

Five causes account for the usual failures.

The window closes before you can read it. The script ran and finished. Add pause, or run it from an open Command Prompt.

"Is not recognized as an internal or external command." The program is not on the PATH, or a path with spaces has no quotes. Put "C:\Program Files\Tool\tool.exe" in quotes and give the full path.

The file is really a .txt. Check the extension first. Explorer hides it by default.

A UNC path will not cd. Command Prompt cannot change into \\server\share. Use pushd \\server\share, which maps a temporary drive letter, and popd to release it.

It works for you and fails for the scheduler. Rights, mapped drives and the working folder all differ for a service account or SYSTEM. Mapped drives belong to a user session, so use full UNC paths in anything unattended.

When to Move From .BAT to PowerShell

Batch is the right size for a sequence of commands. It strains when the job needs data. Microsoft's own cmd reference points people who want more advanced scripting toward PowerShell.

Three signs it is time to switch. The script parses output, such as a CSV or JSON, rather than just printing it. It needs real error handling instead of checking errorlevel after every line. Or it has to run against other computers rather than the one you are sitting at. Our PowerShell commands guide lists the cmdlets to start with.

The same idea exists outside Windows. A bash script plays the role a batch file plays here, and our what is bash guide shows it for admins who work on both.

Picking the Right Tool for the Job

Match the tool to the size of the task. A one-off on one PC is a .bat file. Something that repeats goes in Task Scheduler, with the script writing a log. Anything that handles data or needs error handling is PowerShell. A job that has to reach every device a client owns needs something that can run the script on all of them and bring the output back, which is what OpenFrame does for scripts across a client's devices.

Watch the short version of all this in a walkthrough that creates and runs a batch file from scratch:

.BAT Files, in Short

A .bat file is a text file of CMD commands, saved with the right extension and run from a double-click, a command line or a scheduler. Add pause while you test, move to the script's own folder with %~dp0 when it runs elevated, and move to PowerShell when the job outgrows a list of commands. For a wider list of everyday commands to put inside one, see our CMD commands guide.

"Fae" Grace Meadows

"Fae" Grace Meadows

Lead AI Fairy

Some things defy easy explanation: magic dust, the northern lights… and Flamingo’s AI Angels. Think Charlie’s Angels, reimagined with automation brains and serious RMM (Remote Monitoring & Management) chops. Weird? A little. Effective? Absolutely. That’s the job.

Related Content

Blog Posts

Product Releases

Podcasts

Webinars

Case Studies

Events

Onboarding Guides

Frequently Asked Questions

MSP AI Agents

Yes. In production MSP shops today, 10% to 25% of tickets close before a human opens them. Thread alone has processed 173 million tickets across 750-plus MSP partners at 96% triage accuracy, handing back 490,000-plus technician hours. Agents own the low-risk, high-volume work (password resets, MFA enrollment, known installs, onboarding and offboarding) and flag anything that touches production data or needs judgment for a human to take.
On a five-person desk, reported deployments show $78,000 to $130,000 in annual direct labor savings, roughly 30% fewer escalations, and 15% to 20% better SLA compliance. Broader MSP adoption data adds ticket handling time cut by 45% and five to 12 points of margin, all from reclaimed capacity rather than headcount cuts.

About OpenFrame

OpenFrame isn't built to plug into your stack. It replaces it. Instead of duct-taping a dozen tools together (RMM, MDM, SIEM, patching, remote access, each its own login and bill), we bundle it into one unified platform: RMM, MDM, monitoring, automation, remote access, patch management, security monitoring, and ticketing, plus built-in AI copilots. So "does it integrate with X?" usually means: you won't need X anymore.
Most platforms give you one piece and expect you to bolt the rest on. OpenFrame unifies the whole stack in one place, with AI copilots built in. Fewer logins, fewer bills, less duct tape.
In the cloud, on US soil. Your data stays stateside.
Both. It's built for MSPs and MSSPs alike.
A .bat file is a plain text file of Windows commands, run by the cmd.exe command interpreter one line at a time. Double-click it or start it from a Command Prompt and the commands run in order. It is used for small repeatable jobs such as copying files, mapping drives and running tools.
Right-click the file and choose Run as administrator, which on Windows 11 can sit under Show more options. You can also open Command Prompt as administrator and run the file there, tick Run as administrator on a shortcut, or tick Run with highest privileges in Task Scheduler. Start the script with cd /d "%~dp0" because an elevated window can start in C:\Windows\System32.
Both are text files that run in cmd.exe, and the call command accepts either extension. The .cmd extension is the newer one, and the main difference is how a few commands set ERRORLEVEL. For a new script either works, so keep .bat if your older tools expect it.
The script ran to the end and the window closed with it. Add pause as the last line to keep the output on screen, or open Command Prompt first and run the file from there so the window stays open and any error stays visible.