March 9, 2015 at 12:10 pm
How to append an hostname/computername to a text file using windows batch command? Please suggest
Thanks.
March 9, 2015 at 12:17 pm
I've written the below script but not able to append the hostname to the output file.
@echo off
@break off
@title Create folder with batch but only if it doesn't already exist
@color 0a
cd C:setlocal EnableDelayedExpansion
if not exist "C:\SQL Server Install\" (
mkdir "C:\SQL Server Install\"
if "!errorlevel!" EQU "0" (
echo Folder created successfully
) else (
echo Error while creating folder
)
) else (
echo Folder already exists
)
sc query|findstr "DISPLAY_NAME"|findstr /C:"SQL Server (" > RunningSQLInstances.txt
echo ON
echo ON
FOR /F " tokens=2 delims=()" %i in (RunningSQLInstances.txt) do @echo %computername%\%i
echo ON
echo ON
move /Y "C:\RunningSQLInstances.txt" "C:\SQL Server Install\";
REM-copy "C:\SQL Server Install\RunningSQLInstances.txt" RunningSQLInstances-%date%_%time%-%computername%-%username%.txt
ren "C:\SQL Server Install\RunningSQLInstances.txt" RunningSQLInstances_%date:~-4,4%%date:~-7,2%%date:~-10,2%
REM -ren "C:\SQL Server Install\RunningSQLInstances.txt" RunningSQLInstances_%date%_%time%.txt
@echo ON
cls
Thanks.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply