0

Okay here's another one.

So the idea for this batch uses two loops, but I feel like I lack the proper knowledge but here we go:

Batch code: (Please be advised, that when user's are assigned computers, they are assigned by the description. Not my choice but anyway, it searches for computers owned by the description.)

    @echo off
    echo First and Last Name of User:
    echo.
    set /p name= 
    set desc="assigned to %name%"
    echo.
    dsquery computer domainroot -desc %desc%*
    for /f "delims=," %%a in ('dsquery computer domainroot -desc %desc%*' ) do set CompName=%%a123
    set CompName=%CompName:~4,-3%
    pause
    for /f "delims=" %u in ('wmic /node:%CompName% COMPUTERSYSTEM GET USERNAME^|find "\"') do set userfound=%~nxu
    pause

The batch seems to break at the second loop. I feel as though maybe because the first loop that is assigned a variable, it won't allow for a second for /f command to run properly.

Any suggestions?

Jash
  • 31
  • 2
  • Why the hell do you append 123 to CompName to strip it off in the next step? And do you also strip off the first four chars intentionally? The second for fails because in a batch the for vars `%%u` need two percent signs, solely on the cmd line only one is required. –  May 09 '17 at 22:34
  • The looping parameter in 2nd `for` loop is having problem: it should be `%%u` not `%u`, `%%~nxu` not `%~nxu` –  May 10 '17 at 09:06

0 Answers0