Link to home
Start Free TrialLog in
Avatar of becraig
becraigFlag for United States of America

asked on

Get server names in the AD and populate a text file

I want to query for specific server names and populate a text file with the names of all the servers in the AD.
This is where I am at the moment:

@echo off
for /f "tokens=1 delims=," %%a in ('dsquery computer -name *sql* -limit 10000 ^| find /i "="') do (
  if not "%%a"=="" set ServerName=%%a
)
set ServerName=%ServerName:~4%
 
echo %ServerName%




Can anyone help me here.
Avatar of SysExpert
SysExpert
Flag of Israel image

If this is working on the screen and all you need is a text file then change the last line to

echo %ServerName% >> servlist.txt
 

I hope this helps !
Why don't you use CSVDE

CSVDE -f "C:\COMPUTER.CSV" -r  "(&(objectClass=COMPUTER)(name=*sql*))" -s domaincontrollername
Avatar of becraig

ASKER

The idea behind what I have above is I simply want to parse for the servernames only and write to the text file with the names of all the servers that match that naming convention.
Avatar of becraig

ASKER

Ok here is what it is and what I need:
@echo off
for /f "tokens=2 delims==," %%a in ('dsquery computer -name *sql* -limit 10000 ^| find /i ""') do set ServerName=%%a
)

echo %ServerName% >> serversnow.txt

this is only spitting out one server name, I know there are more servers and I am missing something.

I need to get the results from the dsquery command but stripped out to show only the server name.

so my text file should read
ASKER CERTIFIED SOLUTION
Avatar of SysExpert
SysExpert
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial