Batch Script to Collect Network Information

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nbb
Posts: 1
Joined: 27 May 2016 02:00

Batch Script to Collect Network Information

#1 Post by nbb » 27 May 2016 02:10

Hi

In order to troubleshoot a slow performing network, i need to create a batch script to obtain certain information from a users computer in order to analyze the cause further.. Unfortunately i have no experience with batch scripts, i have messed around with it but haven't been able to make it work as intended..

I need a script that does the following:

- Check if the path C:\NetworkScripts\ already exists
- If not it needs to create the folder "NetworkScripts" on the C:\ drive
- If the folder already exists it needs to collect the output of the following commands:

ipconfig /all
ping 8.8.8.8

Whether it saves them in one document or a seperate document for each command doesn't really matter, but the file name needs to be stamped with a date and time so that i can see the exact date and time the file was created, and so that the files doesn't overwrite itself everytime they run the script.

Does anyone know how to create this?
Thank you..

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: Batch Script to Collect Network Information

#2 Post by kwsiebert » 27 May 2016 08:16

I tossed this together and it does what you requested, but be aware that if your regional settings aren't United States English, the time stamp may not work correctly.

Code: Select all

@echo off
if not exist "c:\NetworkScripts\" md "c:\NetworkScripts\"
cd /d "c:\NetworkScripts\"
for /f "tokens=2-4 delims=/ " %%i in ("%date%") do set TimeStamp=%%k%%i%%j
for /f "tokens=1-4 delims=:. " %%l in ("%time%") do if %%l LSS 10 (set TimeStamp=%TimeStamp:~2%0%%l%%m%%n) else (set TimeStamp=%TimeStamp:~2%%%l%%m%%n)
ipconfig /all>log.%TimeStamp%.txt
ping 8.8.8.8>>log.%TimeStamp%.txt

Post Reply