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

Around 350 pc and servers running windows os, how to  generate windows patch update status report of those pc & servers, information such as last update date, patch installed. powershell script or other ways to generate the report?
0
Hello

In order to backup properly my SQL Database I need to create 2 batch files which will run on 2 scheduled task and will do the following tasks

1)      Daily at 23h PM : STOPSQL.BAT : Stop SQL SERVER Service and Stop SQL Server Agent Service
2)      Daily at 6h AM: STARTSQL.BAT: Start SQL SERVER Service and Start SQL Server Agent Service

What is the recommended solution for the content of these 2 batch files?
Thank you
0
I want to write a batch script which does the following. Can someone please help me in this? Thank you so much in advance!!

1.We get files with naming convention similar to 2604230_VIJAY_TAX_02-NOV-2018.xls in C:\temp\
2. I want to extract the strings before the Underscore("_") from the filename and save it to variables
3. For example from 2604230_VIJAY_TAX_02-NOV-2018.xls filename, I want to extract 2604230, VIJAY, TAX and 02-NOV-2018.xls and save them to variables.
0
I would like to create a batch file to change a record in a text file that contains about 800 records but have no clue how to do it. Here is there current record I am looking to change. The name of the file is TEMPL2.txt (if that matters).

2,0000501,1,2018-08-13,,0000176,Test,,,,Y,Test@Test.com,0501,Business Development Manager,2080,999,,1.01.90.966,2080,,,,2018-08-13

Notice after the email address the number 0501. I would like to change this to 1501 so the final result:

2,0000501,1,2018-08-13,,0000176,Test,,,,Y,Test@Test.com,1501,Business Development Manager,2080,999,,1.01.90.966,2080,,,,2018-08-13
0
Hi there..

I would like to change the following X01 and ABC lines in a text
file from this format:

X01*00010*48*CA***TS*54589652358745*XA*589856562354*UR*000000054585789656~
ABC**PXP*20.1~

to this format:

X01**48*CA*20.1**TS*54589652358745~
ABC**PXP*20.1~

Every time it sees an X01 line I would like to modify it and every time it sees
an ABC line I would like to modify it to the format above.

There could be multiple X01 and ABC lines in any given text file so it's the format of the line changes that would be important and the movement of the data etc..

Is this possible in Powershell or Batch?

Thanks so much in advance.
0
Hi,

I have a source file named 'Get_SubVar_Yr.log' that has these three lines:

Processing...
 ALL.Act_Yr=FY18
getsubstvar completed successfully

I'm trying to set a variable equal to the value after the = on the 2nd line.  So my variable named 'theyear' would equal 'FY18'.

for /f "tokens=1,2 skip=1 delims==," %%A IN ("D:\Get_SubVar_Yr.log") DO @echo %%B

Open in new window


I'm not sure how to resolve the 'delims==' part to start.  Is that possible?
Also do/should I need to skip the first line and did I get that correct?
Will the 3rd line hose anything up?
Is For /f   the correct method in the first place?
1
Task Scheduler has stopped running custom reboot batch files. We've got two of them were the first is scheduled to run every Monday morning. The other is set when we need to run a reboot out of hours for that night.

It has in the past run, but we have discovered it has stopped.

It running on Windows Small Business Server 2011

We've created a test batch file that opens a cmd window that says test and awaits for someone to press a button to continue but that doesn't appear when using task Scheduler.

Any help is appreciated
0
I created a batch file with the following command for test (before I set in production):

TestMe.bat
REM echo off
for /L %%A IN (1,1,10000) do echo %%A 2>&1 | wtee -a outputv2.log & for %%F in ("outputv2.log") do if %%~zF GTR 500 del %%F | echo %date% %time%  File %%F with size %%~zF >> deleted.log

Open in new window


Question:
Why is the date and time not changing after deleting "outputv2.log" and logging in "deleted.log"? Where is the bug or how can I correct it?

For me it seems that on every delete it logs the starting  date and time of the batch file.

deleted.log:
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
1
The zip file is a folder containing 6 files.

Three originals and three examples of the required result.

In each of the original files:
la_162.csv
la_163.csv
la_164.csv

column A contains a heading in A1  and a list of numbers from A2

The requirement is to be able to highlight all original files in the folder and run a script that
1. includes the number from the file name in column B as per the example for each file and
2. renames the amended file to include the heading from Column A in that file name.
EE-folder.rar
0
Is it any example to write a shutdown script such that it will randomly shutdown the Window after 0:00, close the Outlook if it is opened and copy the ost file to the server ?

Thx
0
I am having trouble with my batch files .bat.  The folder names have spaces in them and the commands do not like it.

Powershell also has this problem.

There are many files to process so renaming them manually is not an option.

How can I get around this?
1
Hello experts,

I have the following layout

Root Folder —- with files and subfolders

I need to use robocopy to only copy the files in the root folder and skip any subfolders. Just going after the files at the root level folder but not the subfolders.

Ie

Root folder — has subfolders 1,2,3 and files a,b,c, etc

I only want to copy files a,b,c and any other files but not the subfolders.

Any help?
1
is there a way to add to the windows credential manager via the command prompt
I'm not referring to cmdkey but the actual windows credential manager apparently they are not the same thing.
When I use cmdkey /generic:TERMSRV/server /user:username /pass:password
it works fine it I run mstsc /v:server  
but if I run it from the desktop by clicking on a shortcut it prompts me for the password; however, if I put the credentials in windows credential manager I do not get the prompt

so, is there a a command to add a username and password to windows credential manager ?
I don't want any user interaction I want to run it through a bat script or psexec or something.
Thanks!
0
Batch scripting

Experts,

I have run across an old dos batch script that utilizes something I have never seen.

The script is used to copy a file, but the reasons behind and the uses for the [ ] is what I am looking for.

copy h:filename.txt i:[Spreadsheet]\folder1\folder2

Open in new window

1
Is there any way to list all the folders and files under a particular directory ?

Thx
0
I would like a simple script in .bat, .vbs, or powershell, which will look into a .txt fle and do one of the following, whichever is easier to do:

1.  Whenever it sees specific text such as AD, or DE, or BOG, or STOW..  that it will insert a tilde character (~) just before the text and then save the file with a new name.

OR

2.  Whenever it sees the specific text such as AD, DE, BOG, or STOW, that it would start a new line which starts with those characters, and only start another line when it finds the next set of specific text.

The file resides at:  
C:\Users\user\Desktop\folder\file.txt
And the output should be in the same folder but renamed to:
C:\Users\user\Desktop\folder\fileR.txt
2
Hello experts,

I use the following script the script reported at:
https://www.experts-exchange.com/questions/29123510

which allows me to ping based on multiple loops

I would like add in the script traceroute operation in order to generate ping logs and traceroute based on IP’s reported in config txt file.

Adaptations to include :
-Include traceroute operation in the script
-Change log output name in order to include log-ping_IP_YYYYMMDDMMHHSS, log-traceroute_IP_YYYYMMDDMMHHSS
-Loop parameter will cover ping operation and traceroute operation.

If you have questions, please contact me.
0
Hello experts,

I am looking for a script in order to get the process view of task manager in a csv file.

2018-10-30_11h04_42.png
The various values should be displayed as they are displayed in taskmanager: CPU %, Memory MB etc;;.

If you have already a script that output automatically this type of information could you please share with me?

Thank you again for your help.
0
Hello experts,

I have use the following command to get system information and process list
Processlist
Systeminfo
I would like to extract information from a user, as a result I was wondering if you can help to set up a bat file to output both informations in differents files.
Both output files should generated in the same location as the bat file.

If you have questions, please contact me.
0
Windows Batch file to count a set "N" number of files from a single source folder,merged multiple files together into a single output file that contains <= N number of records, and move processed files to a save directory folder.

Request for a window bat file that can be run from command/CMD prompt.  Windows 7 environment.

Windows Batch file to copy a set "N" number of files from a single source folder to an output file, move processed records to a single save folder.  The single source directory may contain 1 up to a million files.  
Need to copy 200 files at a time to a newfile_N+ that should contain <= 200 files per newfile_N+ until all records have been read and processed.

Input file extension: *.hl7
Output file newfile_N+ extension: *.txt

Source directory - C:\temp\source
Destination directory - C:\temp\output\newfile_N+.txt
Destination directory - C:\temp\processed

For the purpose of demonstration I have attached (5) sample hl7 files.
Each newfile_N+.txt file should contain <= 2 records per file.

Prior to kicking off the batch file.  All (5) source files would be all be in the (C:\temp\source) directory.
Upon completion of the batch program running.  The expected output once the bat file has run would result in the following:

C:\temp\source
      dir: contains no files *.hl7 files
      
C:\temp\output
 dir: newfile.txt, newfile1.txt, newfile2.txt
      Note: Each of these files contains <=2 records each, max is 2 records per file
      ==> newfile.txt …
1
Hello experts,

I have the following batch file, reported at:
https://superuser.com/questions/309403/batch-file-to-write-ping-results-to-a-text-file
@echo off

set/p host=host Address: 
set logfile=Log_%host%.log

echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
    timeout 1 >NUL 
    GOTO Ping)

Open in new window


I would like to add some enhancement
-Be able to report the various ip in a config-file.txt
-Be able to output multiple files related to ip reported.
-Parse the time of ping for example I would just to ping during 2 minutes and then exit.


If you have questions, please contact me.

Regards,
0
I would like to join two as many text files that are found in C:\Files\.... into one file ending in .txt
with no lines that it finds in between the data in one text file and other etc..
0
Batch script to check for IP address and install if errorlevel==0 but exit if errorlevel==2 not working.

The script below is to determine if an end user is connected via vpn.  

When connected to VPN ipconfig | find returns "2"
When not connected it returns "0"

The script works when I am not connected to VPN.  When I'm connected to VPN, I run ipconfig | find manually and I get "2" but the script just flashes and does nothing.  I can't figure out what I've done wrong in this script.

@echo off

REM Check to see if an IP address in the VPN range is present.
REM Install Cisco AC if no VPN IP address is present.
REM Exit withoug install if VPN address is present

ipconfig | find /c "168.32." >NUL 2>NUL
 if "%errorlevel%"=="2" goto VPN
 if "%errorlevel%"=="0" goto Install

Install:

echo.
echo This is install!
Pause
goto End

VPN:

echo.
echo SCCM is attempting to install Cisco AnyConnect (your VPN) over a VPN connection!
echo.
echo This will cause a disconnect and possible loss of work.
echo.
echo You can attempt again when you are on site.
echo.
Pause



End:

Exit /b 0
1
Request for a window batch file that can be run from command/CMD prompt.  Windows 7 environment.

Windows Batch file to move a set "N" number of files from a single source folder to a destination folder.  The single source directory may contain 1 up to a million files.  Need to copy 200 files at a time to a destination folder_N+ that should contain <= 200 files per destination directory.

Once all the files are moved to the destination folders, would like to merge the multiple files per individual destination folder into one single file. (copy *.hl7 newfile.hl7)

File extension: *.hl7
Source directory - C:\temp\source
Destination directory - C:\temp\outputN+

For the purpose of demonstration I have attached (5) sample hl7 files.  
These (5) files would be all be in the (C:\temp\source) directory.  
Expected output would result in the following:

C:\temp\output
 dir: new 1.hl7, new 2.hl7
 copy *.hl7 newfile.hl7

C:\temp\output1
 dir: new 3.hl7, new 4.hl7
 copy *.hl7 newfile.hl7

C:\temp\output2
 dir: new 5.hl7
 copy *.hl7 newfile.hl7

Note: The folder names may contain spaces, also the file names may contain spaces.
source.zip
0
I would like to search a folder, for example C:\Attachement\Inbox..  for any files that start with the  following  INBOUND123..... .in  
then I could like to copy if found to another folder called C:\Attachments\Transferred..

What batch command can I use to do this?
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.