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

x
?
Solved

Remove extra spaces from a pipe in command prompt written to a text file

Posted on 2013-12-09
8
Medium Priority
?
341 Views
Last Modified: 2013-12-16
I have the following DSquery:
DSQUERY USER OU=firstou,OU=secondou,OU=thirdou,DC=child,DC=domain,DC=domain,DC=com| DSGET USER –SAMID >USERSLIST.TXT

Open in new window

The command works well, I get a list of all users in that specific OU in a text file. Each user is listed in 1 line. But the problem is before the username and after the user name there are white space... How do I remove these whitespaces?
0
Comment
Question by:levertm
[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
  • 4
  • 3
8 Comments
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39707072
Try this at a command line (if using in a BAT script change the %A's to %%A's):

(for /f %A in ('DSQUERY USER OU=firstou,OU=secondou,OU=thirdou,DC=child,DC=domain,DC=domain,DC=com ^| DSGET USER –SAMID') do @echo %A) > USERSLIST.TXT

Open in new window

~bp
0
 

Author Comment

by:levertm
ID: 39707200
Error:

dsquery failed: 'firstou' is an unknown parameter.
type dsquery /? for help.dsget failed: value for 'target objet for this command' has incorrect format.
type dsget /? for help.


Of course I subsituted for my real OU/DC names.
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39707524
I don't have the ability to test this, but try this change:

(for /f %A in ('DSQUERY USER "OU=firstou,OU=secondou,OU=thirdou,DC=child,DC=domain,DC=domain,DC=com" ^| DSGET USER –SAMID') do @echo %A) > USERSLIST.TXT

Open in new window

~bp
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

by:levertm
ID: 39708517
I get the following error:

dsget failed: value for 'target objet for this command' has incorrect format.
type dsget /? for help.
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39709159
Setting up some testing here...

~bp
0
 
LVL 57

Assisted Solution

by:Bill Prew
Bill Prew earned 1000 total points
ID: 39709615
Interesting, it looks like the dash in front of the SAMID isn't actually a proper dash.  Give this a try, I corrected that character.

(for /f %A in ('DSQUERY USER "OU=firstou,OU=secondou,OU=thirdou,DC=child,DC=domain,DC=domain,DC=com" ^| DSGET USER -SAMID') do @echo %A) > USERSLIST.TXT

Open in new window

~bp
0
 
LVL 20

Accepted Solution

by:
compdigit44 earned 1000 total points
ID: 39710092
Have you tried using powershell to see if you are able to control the output better???

http://technet.microsoft.com/en-us/library/ee617241.aspx
0
 

Author Closing Comment

by:levertm
ID: 39721999
Thanks guys, I used Powershell instead.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

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