Solved

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

Posted on 2013-12-09
8
308 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
  • 4
  • 3
8 Comments
 
LVL 51

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 51

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
 

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 51

Expert Comment

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

~bp
0
 
LVL 51

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 19

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

Join & Write a Comment

[b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

746 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

12 Experts available now in Live!

Get 1:1 Help Now