Solved

Get server names in the AD and populate a text file

Posted on 2008-10-01
7
251 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 28

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 28

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
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 Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now