Solved

Get server names in the AD and populate a text file

Posted on 2008-10-01
7
257 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:becraig
  • 2
  • 2
7 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 22620958
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 !
0
 
LVL 23

Expert Comment

by:Malli Boppe
ID: 22621633
Why don't you use CSVDE

CSVDE -f "C:\COMPUTER.CSV" -r  "(&(objectClass=COMPUTER)(name=*sql*))" -s domaincontrollername
0
 
LVL 29

Author Comment

by:becraig
ID: 22622541
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.
0
 
LVL 29

Author Comment

by:becraig
ID: 22627900
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
0
 
LVL 63

Accepted Solution

by:
SysExpert earned 500 total points
ID: 22631015
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

)

You need to put the echo inside the do loop
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question