Solved

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

Posted on 2013-12-09
8
333 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 54

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 54

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
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.

 

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 54

Expert Comment

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

~bp
0
 
LVL 54

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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