Solved

Get server names in the AD and populate a text file

Posted on 2008-10-01
7
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

719 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