becraig
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.
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.
Why don't you use CSVDE
CSVDE -f "C:\COMPUTER.CSV" -r "(&(objectClass=COMPUTER)( name=*sql* ))" -s domaincontrollername
CSVDE -f "C:\COMPUTER.CSV" -r "(&(objectClass=COMPUTER)(
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.
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
@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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
echo %ServerName% >> servlist.txt
I hope this helps !