@echo off
set userdomain=%1
set username=%2
set CN=""
for /F "delims=" %%a in ('dsquery user dc^=%userdomain%^,dc^=main^,dc^=ntu^,dc^=edu^,dc^=sg -samid %username%') do set CN=%%a%
rem echo.
rem echo %userdomain%\%username%
rem echo %CN%
rem echo.
if %CN%=="" (
echo %userdomain%\%username%^|N
) ELSE (
echo %userdomain%\%username%^|Y
)