I have a CMD file which extracts users from an Active Directory group then trims it so only the username is displayed in the output file GroupMemberTrim.txt.
It works fine, however I would like to use dynamic file names instead of static
GroupMemberExtract.txt -> %groupname%-Extract.txt
GroupMemberTrim.txt -> %groupname%-Trim.txt
When I change this it breaks the FOR loop so the %%a variable does not read in the contents of %groupname%-Extract.txt instead it reads the filename %groupname%-Extract.txt as the %%a variable.
Does anyone have any ideas how this could be fixed?
@echo off CLS :GroupsMembersExtract echo. set /p groupname=enter groupname: echo. echo. dsquery * domainroot -filter "(&(objectClass=group)(name=""%groupname%""))" -l -d DomainName -attr member >>GroupMemberExtract.txt :GroupsMembersTrim CLS setlocal enabledelayedexpansion FOR /F "tokens=1 delims=," %%a IN ( GroupMemberExtract.txt ) DO ( set oldName=%%a set newName=!oldName:~3! echo !%newName!>>GroupMemberTrim.txt ) SETLOCAL DISABLEEXTENSIONS :END