How to Export a List of All Services to CSV in Batch Script
Generating a comprehensive report of all Windows services is a common requirement for system audits, compliance checks, and machine inventory. While viewing services in the GUI is helpful for quick checks, a CSV (Comma-Separated Values) file is much better for long-term documentation because it can be opened in Excel, imported into a database, or compared against previous versions to spot changes.
This guide will explain how to use the wmic command to export a clean, structured list of all services directly to a CSV file.
The Tool: WMIC with CSV Formatting
The most efficient way to generate a CSV from the command line is using the wmic (Windows Management Instrumentation Command-line) tool. It has a built-in /format:csv switch that handles the column creation and data alignment for you.
Basic Implementation
@echo off
set "OutputDir=%~dp0"
set "OutputFile=%OutputDir%ServiceAudit_%COMPUTERNAME%.csv"
echo [ACTION] Generating service report...
:: Get Name, DisplayName, StartMode, and Current State
wmic service get Name, DisplayName, StartMode, State /format:csv > "%OutputFile%" 2>nul
if %errorlevel% equ 0 (
echo [SUCCESS] Report saved to: %OutputFile%
) else (
echo [ERROR] Export failed. Ensure you are running as Administrator.
)
pause
Customizing the Export Columns
You don't have to export everything. You can pick exactly which pieces of information you want in your report. Common attributes include:
| Attribute | Description |
|---|---|
| Name | Internal system name (e.g., Spooler). |
| DisplayName | Human-readable name (e.g., Print Spooler). |
| StartMode | Startup type (Auto, Manual, Disabled). |
| State | Current status (Running, Stopped). |
| StartName | The account the service runs under (e.g., LocalSystem). |
| PathName | The location of the executable file. |
Script: Full Audit Report
@echo off
set "OutputDir=%~dp0"
set "OutputFile=%OutputDir%Service_Audit_Report.csv"
echo [ACTION] Running full service audit...
wmic service get Name, DisplayName, StartMode, State, StartName, PathName /format:csv > "%OutputFile%" 2>nul
if %errorlevel% equ 0 (
echo [SUCCESS] Full audit saved to: %OutputFile%
) else (
echo [ERROR] Export failed. Ensure you are running as Administrator.
)
pause
Cleaning Up the Output
The wmic tool has one quirk: its output often contains extra blank lines and uses Unicode encoding that some applications find difficult to process.
To create a "Clean" CSV that is ready for immediate use in other scripts or tools, you can filter out the blank lines.
@echo off
set "TempFile=%TEMP%\svc_raw_%RANDOM%.tmp"
set "FinalFile=%~dp0Services_Clean.csv"
echo [ACTION] Extracting and cleaning data...
:: 1. Generate the raw CSV to a temp file
wmic service get Name, DisplayName, StartMode, State /format:csv > "%TempFile%" 2>nul
if %errorlevel% neq 0 (
echo [ERROR] WMIC query failed.
del "%TempFile%" >nul 2>&1
pause
exit /b 1
)
:: 2. Use 'type' to convert from Unicode to ANSI
:: Use 'findstr' to remove empty lines (lines with no printable characters)
type "%TempFile%" | findstr /r /v "^$" > "%FinalFile%"
:: 3. Delete the temp file
del "%TempFile%" >nul 2>&1
echo [SUCCESS] Clean report saved to: %FinalFile%
pause
How to Avoid Common Errors
Wrong Way: Using "sc query" to create a CSV
Some users try sc query > services.csv.
Why it fails: sc query returns multi-line blocks of text for each service. It is not structured as rows and columns. Trying to open this in Excel will result in one giant, unreadable column of fragmented data.
Correct Way: Use wmic service which is designed for structured data output.
Problem: Permissions on the C: Root
If you try to export directly to C:\services.csv, the command will fail with "Access Denied" on modern versions of Windows.
Best Practice: Always export to the script's own directory (%~dp0), a subfolder, or the user's desktop (%USERPROFILE%\Desktop).
Best Practices and Rules
1. Administrative Privileges
To get a full list that includes protected third-party and security-related services, you must run your Batch script as an Administrator.
2. Header Knowledge
The first column in a wmic /format:csv export is always the "Node" (the name of the computer). This is useful when combining reports from multiple machines. If you don't need this column, you can remove it in Excel or use a script to strip the first field.
3. Timestamping Your Reports
If you run this audit periodically, add a timestamp to the filename so you can keep a history of your services.
:: Create a timestamp from the date (format varies by locale)
set "tstamp=%date:~-4%%date:~4,2%%date:~7,2%"
wmic service get Name, State /format:csv > "%~dp0Services_%tstamp%.csv" 2>nul
Conclusions
Exporting your services to CSV via Batch script is an essential step for professional system documentation. By using wmic with the /format:csv switch, you transform a complex, real-time database into a static, manageable file that is ready for analysis and archiving. This simple automation ensures that you always have a clear record of your system configuration for troubleshooting or security audits.