Windows Batch

12K

Solutions

11K

Contributors

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

Share tech news, updates, or what's on your mind.

Sign up to Post

HI,

I'm looking for help writing a batch file.

I want to use it as part of a start up GPO,

Install an MSI silently, if the folder already exists skip the install, report the results to a temp.log.

Can someone please assist - thanks
1
Hello experts,

I am looking for a windows batch (robocopy) to copy files from strSourceFolder to strDestinationFolder with specific extension and with a creation date equals to 201900801.
If you have questions, please contact me.
0
Hello experts,

I have the following procedure which allows me to append log files on specific folder:
@echo off
setlocal

set BaseDir=B:\EE\EE29154094\Files
set MergeFile=B:\EE\EE29154094\merge.csv

echo.filename;datemodified;content>"%MergeFile%"

for %%A in ("%BaseDir%\*.*") do (
    if /i NOT "%%~A" == "%MergeFile%" (
        for /f "tokens=*" %%B in ('type "%%~A"') do (
            echo.%%~nxA;%%~tA;%%B>>"%MergeFile%"
        )
    )
)

Open in new window


I would like to add the following requirements
-Be able to report a date stamp to append based on this date
Example:
DateStamp: 15
Append files newer or equal than 15 days.
If you have questions, please contact me.
0
Hi,
I want to run a windows batch file on a remote computer using PowerShell. I have tried with this following command but didn't work.

Invoke-Command -ComputerName "ccccccc" -credential domain\xxxx -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /E 'E:\_deployment\ServicePack\Install_ServicePack.bat'"}

Please help
0
I have the following batch file now I want to add STEP 1 STEP 2 if STEP 1 FAILED then goto next step and send email or generate output in txt

powershell.exe -executionpolicy bypass -file J:\Backup\EnableTCP-IP_Named_Pipes.ps1
powershell.exe -executionpolicy bypass -file J:\Backup\Restart-SQL_Server.ps1
if errorlevel 1 echo Unsuccessful > J:\Backup\result.txt
if errorlevel 0 echo command executed successfully > J:\Backup\result.txt

Thanks
0
Hi Experts,
I am looking for a program that will list all PC names, browser names and versions within the network.
Would prefer it to be done either as a DOS command, batch file or VBA.
Thanks
0
Hello experts,
I have the following script which allows me to create monthly folders and move files.

 
@echo off
setlocal EnableDelayedExpansion


rem Get current date
for /f "tokens=2 delims==" %%G in ('wmic os get localdatetime /value') do set datetime=%%G

rem get year, month, day variables
set Year=%datetime:~0,4%
set Month=%datetime:~4,2%
set Day=%datetime:~6,2%


rem Define file and folder locations
set BaseDir=%cd%
set InputFolder=D:\
set LogFolder=D:\HISTO\%Year%\%Year%-%Month%


rem Make sure needed folders and files exist
if not exist %LogFolder% md %LogFolder%
if not exist %InputFolder% exit /b
if not exist "%InputFolder%\*.csv" exit /b

rem Copy csv files to log folder
xcopy "%InputFolder%\*.csv" %LogFolder% /Y

Open in new window

I would like to take it as a reference to add the following requirements:

Check modified date of files to move. Move files older than 2 days on it respective monthly folder.
Example :
Þ      Toto.csv has a modified date equal to 2019/07/13 it should be moved to 07-2019 folder.
Þ      Titi.csv has a modified equal to 2019/08/12 it should not be moved as it hasn’t a modified date older than 2 days.
If you have questions, please contact me.
Thank you for your help.
0
Hi Experts,

How can I modify this DOS command to only look at files created after a certain date?

Thanks
0
Hello experts,
I have the following batch which allows me to count files on specific folder:
@echo off
setlocal enableextensions
set count=0
for %%x in ("C:\Temp") do set /a count+=1
echo Number of csv files: %count%
endlocal
pause

Open in new window


I was wondering how to put:
-/d option to specify files with a date modified older than 30 days
-/s option to proceed recursively

If you have questions, please contact me.
Thank you for your help.
0
I have a subtitle file (srt format) file like this :


1
00:00:00,701 --> 00:00:20,033
ffdfdfddfdf
2
00:00:20,701 --> 00:00:30,033
fdfddfdgdgdgdg
3
00:00:32,000 --> 00:00:38,074
hhhghghggh
4
00:00:42,701 --> 00:00:45,033
vvvffffgdfg

those are only the first 4 lines,but it is very long. What I want to do is to write a batch script that does the following things :

1) it removes all the sentences that are under the timings. In this particular case are : "ffdfdfddfdf" ; "fdfddfdgdgdgdg" ; "hhhghghggh" ; "vvvffffgdfg" ;

2) it changes the sentences that I mentioned above with the number with which each subtitle starts. In this particular case with : "1" ; "2" ; "3" ; "4" ;

So,at the end it should do something like this :


1
00:00:00,701 --> 00:00:20,033
1
2
00:00:20,701 --> 00:00:30,033
2
3
00:00:32,000 --> 00:00:38,074
3
4
00:00:42,701 --> 00:00:45,033
4

that's all. Really I can't do that manually because it takes a lot of time. And I don't know enough how the batch scripting works. I don't know any other language at all. I'm sorry but I can't give you a small piece of code to fix. I hope to find someone that can understand my situation and that can write the code for me. very thanks.
0
I would like to scan 600 PCs & 30 servers that join our AD for
files with a certain hash (given by our threat intel).  Sometimes
we can get hundreds of IOC hashes (last one was 700+) in 1 day.

However, using Trendmicro EDR, it's getting very inefficient as
we have to use Mandiant IOC converter to convert one hash at
a time to be appended to a  .ioc file that looks like below.

So I'm looking for free solutions that either can scan all the AD
endpoints for the presence of hash (I currently have batch scripts
that could scan each time a user logon to a PC for registry key
IOCs) but MS fciv tool can't possibly rescan all that millions of
files (as this could slow down the login by users) & store their
hashes   or   I'll need something better than Mandiant IOC
converter that could read in the entire batch of hashes.

That xxx.ioc file contains the following :

<?xml version="1.0" encoding="US-ASCII"?>
-<ioc xmlns="http://schemas.mandiant.com/2010/ioc" last-modified="2019-07-25T03:02:52" id="2146113a-1513-4be6-b07e-f43969847a6a" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<short_description>Sample</short_description>

<authored_date>2017-09-26T02:58:26</authored_date>
<links/>

-<definition>
-<Indicator id="a1c825b0-ae7f-4461-85dd-25a20720acac" operator="OR">          <== this value is given by the converter
-<IndicatorItem id="333cd85e-637e-4889-b68a-a5f54e1e8d40" condition="is">   <== this value…
0
The request is fairly simple :
I have a script/batch that some of my friends would like to use (so the request can not be implemented by group policy).
Let's call my script "Batch_a.bat".
"Batch_a.bat" is to be run at user login   (it checks something).
I want another script/batch that will copy "Batch_a.bat" to "C:\zmau" and then add a shortcut into Startup or added to registry under "HKCU\Microsoft\windows\current version\run key"
I would be happy to get both options.


Thanks
zmau
0
Hello experts,
I have a bunch of log files to analyse. They are located in the same folder.
They don't contain common header and they can contain multiple lines.
I would like to append them into a single CSV file with it file name.
The idea is to have the following:
File name; contain; Date modified (related to file)
If a file contains multiple lines. File name should be dupplicated.
Example:
File 1; line 1; Date modified
File 1; line2; Date modified
If possible have a header with the following:
File name; content; Date modified
If you have questions, please contact me.
0
Hello experts,

I have a root in which I have multiple folders and files.
I am looking for a procedure that allows me to:

1)Based on a config-csv-replacement in which I am going to report as of line one Current_Value;New_Value replace literally Current_Value by New_Value
2)Example: toto;tata. toto value should be replaced in all the files located in Root folder and subfolders
3)Log file should be generated to report files in which the replacement took place
4)config-csv-replacement should support multiple lines entries. If config-csv-replacement is complicated to set up, I am in to report Current_Value;New_Value lines in the script

If you have questions, please contact me.
Thank you for your help.
0
Running MySql version 5.7 on Windows 7 Pro.  I am learning MySql .
My goal is to put the MySql password into a file so I don’t have to put the plain text password into batch files I want to invoke .There is much I do not understand about the relationship between MySql and Windows permissions.

Before executing mysql_config_editor, I would manually navigate to the
cd “Program Files\Mysql\Mysql Server 5.7\bin    folder
   and then type             mysql
  I would get a prompt for password.  I enter the password and the MySql command prompt appears.

I read about mysql_config_editor.  So I typed:
  mysql_config-editor  set –user=root –password
  The   mysql_config-editor prompted me for a password .  I entered the password.

  Then I navigated to the bin folder as above.
  I typed          mysql and this time the mysql command prompt immediately appears, no prompt for password.
  The mysql 5.7 manual says the   mysql_config-editor  will create a file called mylogin.cnf  .  I have searched all the drives on my Windows 7 computer and cannot find this file.  Yes, I am logged in as administrator, I have full rights.

So I thought now, when I execute a Windows batch file,  I just need to enter the –user=root command in the batch file  and MySql will log in as user root without any need for me to provide a password.  And this works as long as I am logged in as administrator.

Questions:
Q1.)  I cannot find any file called mylogin.cnf .  I cannot find any file …
0
Hello experts,
I am trying to create copy 100 times specific file however I just got one file copied
for /l %A in (1,1,100) do copy /y ^
"C:\temp\file.txt" ^
"C:\temp\file.txt%A.txt

Open in new window

Could you please advice on this?
Thank you for your help.
0
Hello experts,
I have the following procedures reported at: https://www.experts-exchange.com/questions/29153639/
Batch approach
@echo off
setlocal

set BaseDir=B:\EE\EE29153505\Base
set DestLog=B:\EE\EE29153505\DestLog
set DestCsv=B:\EE\EE29153505\DestCsv

for /f "tokens=*" %%A in ('findstr /m /b /v /c:"0;" "%BaseDir%\*.log"') do (
    move "%BaseDir%\%%~nxA" "%DestLog%"
    move "%BaseDir%\%%~nA.csv" "%DestCsv%"
)

Open in new window


Powershell approach
$sourceFolder = 'C:\Temp\input'
$targetFolderLog = 'C:\Temp\output'
$targetFolderCsv = 'C:\Temp\output2'
Get-ChildItem -Path $sourceFolder -Filter *.log |
	Select-String -Pattern '^[^0]' -List |
	ForEach-Object {
		Move-Item -Path $_.Path -Destination $targetFolderLog
		Move-Item -Path $($_.Path -replace '\.log$', '.csv') -Destination $targetFolderCsv
	}

Open in new window

Which allows me to move log files and it csv equivalent to specific folder if at least one line of log file start with a value different that 0.
I would like to cover additional needs:
-Execute the procedure during 10 hours. As a result I need a WaitingTime of 10 hours (time that procedure will be active) and a LoopRecurrency variables of every 30 second (time that procedure need to check in reference folder)
-Copy (instead of moving) csv file to csv-error folder and log file to log-error
-Generate and append csv files and log files in listing Csv-error.csv & Log-error.csv files involved by the copy reported in previous step.
If you have questions, please contact me.
Thank you for your help.
1
I need to use the SOX utility to loop through and merge a bunch of audio files. I have 81 unique audio files and need to merge each one with an intro audio tag that is a single file. For instance, I have audio files File1.mp3-File81.mp3 and need to merge the intro audio file Intro. mp3 with each one. The intro.mp3 needs to be placed at the beginning so likely needs to be listed first in the sox command. I think the basic sox command is "sox -m file1.wav file2.wav output_file.wav".  All 81 unique audio files and the intro file are combined into a single folder. So I am looking for a batch statement to loop each one with sox. I also need the batch to rename the output file as EPR5007.mp3, sequencing each merged file in increments of 1, so EPR5008, EPR5009, etc.
0
Hello experts,

I would like to cover an additional need related to question https://www.experts-exchange.com/questions/29153505
Solution proposed move log files from input to output if one file contains at least one line which doesn't start with 0.

Powershell approach:

$sourceFolder = 'C:\Temp\input'
$targetFolder = 'C:\Temp\output'
Get-ChildItem -Path $sourceFolder -Filter *.log |
	Select-String -Pattern '^[^0]' -List |
	ForEach-Object {Move-Item -Path $_.Path -Destination $targetFolder}

Open in new window


Batch approach:
for /f "tokens=*" %%A in ('findstr /m /b /v /c:"0;" "C:\TEMP\BASEDIR\*.log"') do move "%%A" "C:\TEMP\DESTDIR"

Open in new window


Additional need:

In input folder I have .log file and also it .csv file equivalent example : ReqXXXX.log and ReqXXXX.csv,

I would like:
-move log file in output (as is)  
-move csv file equivalent into an output2 folder

Assumption:
-Every log file has it csv equivalent.

If you have questions, please contact me.
Thank you for your help.
2
Hello,
I have a temp folder which contains multiple files.
I am looking for a procedure to launch every 1h to move from C:\temp to C:\Output the 50 newest files.
Example:
I have 700 files in C:\temp.
I execute the procedure and I move the 50 newest files.
One hour after I execute the procedure and I have the 50 newest.
The idea is to move the various files progressively.
If you have questions or another approach, please lest me know.
Thank you for your help.
1
I have the following script that executes a program as follows:

@echo off
start /d "c:\Program Files\Hyena" stexport.exe /CONFIG=C:\EP\Export_Services\HYENA_EXPORT_SERVICES.INI

The batch and the installed program it starts both operate on the c drive of the same windows server with network admin rights. I want to create a shortcut on a workstation desktop of a standard user who can execute the script; however, the program must ultimately execute with the authority of a domain admin account (not a standard user who initially executes it).

In other words, if a standard user executes this batch script (as it is written now) it will only execute with the permissions of the user who initiates it and I need additional script to add to it that will execute the program as a domain admin.
0
Hello experts,
I have in a root folder multiple .log file success file contains 0 as start string.
I am looking for a procedure to move all log files which have at 0 as start string at least for one line (Header line 1 should be excluded).
Possible to have a a windows batch & Powershell or VBS?
Thank you for your help.
0
Hello experts,
I have in a specific folder multiple csv files.
I am looking for a procedure to add specific string at the end based on header reported.
The idea is to have
Header=Header1,Header2
EndString = v2

The procedure should allows me to add end string in multiple fields reported.


I attached dummy file.

In dummy file I expect to have adding “_v2” for Field ID and NewID
Header=ID;NewID
EndString = _v2

If you have questions, please contact me.

Thank you for your help.
Dummy-file.csv
0
Running MySql version 5.7 on Windows 7 pro.  I am not a MySql expert.

Before I posted this question I searched Experts-Exchange for mysql_config_editor.  No results were found.

I am trying to use mysql_config_editor .  I have read the information in the v5.7 manual .  The commands shown  in the manual do not work.

First, the manual shows mysql_config_editor running from a shell command.  I have found I have to manually start the mysql command line to get mysql_config_editor to run.  

The manual says to print the information in mylogin.cnf I should type:
  print –all

This does nothing.  So I am confused and the MySql manual is not helping me.

Questions:  
 -  I want to start mysql from a Windows batch file .  I do not want to put the password in plain text in the batch file.  The 5.7 manual says the password can be put into the mylogin.cnf file.  May be this is the wrong thing to do.   Where should I put the password ?

- I searched all of my drives.  I cannot find a mylogin.cnf file.  May be I’m trying to edit a nonexistent file. What is the name of this file in a Windows installation?

- In what file would you put the password?
0
Hello experts,

I am looking for a procedure in order to remove folders located in a RootFolder
and exclude from the removal folders reported in a txt file.
Values to report in txt file: folder name and not folder path.

To keep in mind:
-Windows or Powershell approach are welcome
-Drill down mode not necessary
-RootFolder should be a variable to declare
-Log file to generate with folders removed

If you have questions, please contact me.
Thank you.
0

Windows Batch

12K

Solutions

11K

Contributors

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.