Question

I have the following in myFile.txt:

samid xxuserMike xxuserDave xxuserSue dsget succeeded

I'd like to use a batch commands to make it: "xxuserMike" "xxuserDave" "xxuserSue"

Side note, the original file is created using dsquery / dsget to make a list of users from a specific group in AD. If there is a way to format that output from the start, all the better. The command I'm using is: dsquery group -name "myADgroup" | dsget group -members | dsget user -samid > myFile.txt

Was it helpful?

Solution

Try this:

@echo off
setlocal enabledelayedexpansion
(for /f "skip=1" %%a in (
  'dsquery group -name "myADGroup"^| dsget group -members^| dsget user -samid'
  ) do ( 
    set l="%%a"
    echo(!l:"dsget"=!
))>myfile.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top