Solved

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

Posted on 2013-12-09
8
335 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 55

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 55

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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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 55

Expert Comment

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

~bp
0
 
LVL 55

Assisted Solution

by:Bill Prew
Bill Prew earned 250 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 250 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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