I put together a script to take ouy out from a dsquery and create a list of FQDNs.
The script was working, I closed the command window, opened a new one and now the script does not work.
Please help
The script is below
@echo off
for /f %%x in (computers.txt) do (
echo %%x
set mystr=%%x
for /f "useback tokens=*" %%a in ('%mystr%') do set mystr=%%~a
set mystr=%mystr:CN =%
set mystr=%mystr:DC =.%
set mystr=%mystr:Computers=%
set mystr=%mystr: =%
echo %mystr%
)
script was working, now it will not
Moderator: DosItHelp
Re: script was working, now it will not
Hi df9870,
The reason is the expansion phase of the variable.
The %var% is only expanded once, at the beginning of the block ().
So you only see the value before you entered the block.
If you want to use the current value use the delayed expansion syntax.
jeb
The reason is the expansion phase of the variable.
The %var% is only expanded once, at the beginning of the block ().
So you only see the value before you entered the block.
If you want to use the current value use the delayed expansion syntax.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
for /f %%x in (computers.txt) do (
echo %%x
set mystr=%%x
for /f "useback tokens=*" %%a in ('!mystr!') do set mystr=%%~a
set mystr=!mystr:CN =!
set mystr=!mystr:DC =.!
set mystr=!mystr:Computers=!
set mystr=!mystr: =!
echo !mystr!
)
jeb