[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Get server names in the AD and populate a text file

Posted on 2008-10-01
7
Medium Priority
?
270 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…

656 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