- 1 year ago
Tasklist csv script
To create a script that uses the tasklist
command to output process information in CSV format, you can use a batch script or PowerShell script. Here's an example of how to do it in both:
Batch Script (tasklist_csv.bat):
batch@echo off
REM Run tasklist command and redirect output to a temporary text file
tasklist /FO CSV > temp_tasklist.csv
REM Process the temporary CSV file and remove unnecessary double quotes
(for /f "tokens=*" %%a in (temp_tasklist.csv) do (
set "line=%%a"
echo !line:""=!
)) > tasklist.csv
REM Clean up the temporary file
del temp_tasklist.csv
PowerShell Script (tasklist_csv.ps1):
powershell# Run tasklist command and convert output to CSV format
$tasklistOutput = tasklist /FO CSV
# Convert CSV string to array of lines
$tasklistLines = $tasklistOutput -split [Environment]::NewLine
# Process the lines and remove unnecessary double quotes
$tasklistLines | ForEach-Object {
$line = $_ -replace '""', '"'
$line
} | Out-File -Encoding utf8 tasklist.csv
To use the script, save it in a file with the respective extension (.bat
for the batch script or .ps1
for the PowerShell script). Then, run the script in a command prompt (batch) or PowerShell prompt (PowerShell) to generate the tasklist.csv
file containing the tasklist information in CSV format.
The CSV file will have columns such as "Image Name," "PID," "Session Name," "Session#" and so on, containing information about the running processes.
Please note that the CSV output may vary depending on your system's locale settings, so you may need to adjust the script accordingly if you need specific column names or different CSV formatting.