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
Solved

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

Posted on 2013-12-09
8
329 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 53

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 53

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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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 53

Expert Comment

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

~bp
0
 
LVL 53

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

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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