batch script help - using if function

Hi, i need help writing part of the batch script to do the following:

1. run nltest /sc_query:domain.name
2. if command returns result:

C:\>nltest /sc_query:domain.name

Flags: 0
Trusted DC Name
Trusted DC Connection Status Status = 1311 0x51f ERROR_NO_LOGON_SERVERS
The command completed successfully

2.1  run another command x

3. if command returns result:

C:\>nltest /sc_query:domain.name

Flags: 10 HAS_IP
Trusted DC Name \\dc.domain.name
Trusted DC Connection Status Status = 0 0x0 NERR_Success
The command completed successfully

3.1 end script, exit

I'd imagine best would be to read line "Trusted DC Name" and if matched or not  "Trusted DC Name \\dc.domain.name" do further actions.


Thanks in advance
ExcelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
This will get the whole status line into variables that you can then query:
@echo off
setlocal
set QueryDomain=%UserDnsDomain%
for /f "tokens=6,7* delims== " %%a in ('nltest.exe /sc_query:%QueryDomain% ^| find.exe /i "Trusted DC Connection Status Status"') do (
	set ResultDec=%%a
	set ResultHex=%%b
	set ResultState=%%c
)
echo Query result: %ResultDec%, '%ResultState%'
if "%ResultDec%"=="0" (
	echo Secure channel OK.
	goto :eof
)
echo Trying to correct ...
REM Run x here ...

for /f "tokens=6,7* delims== " %%a in ('nltest.exe /sc_query:%QueryDomain% ^| find.exe /i "Trusted DC Connection Status Status"') do (
	set ResultDec=%%a
	set ResultHex=%%b
	set ResultState=%%c
)
echo Query result after fix: %ResultDec%, '%ResultState%'
if "%ResultDec%"=="0" (
	echo Secure channel OK.
	goto :eof
)
echo Secure channel still not OK!

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ExcelAuthor Commented:
Thank you oBdA, better than expected!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.