Get Full name
Description
this small snippet can be used to get the first and the surname in different variables.
you can use the current user or type a username.
Please make sure there is a folder c:\temp
@echo off
REM choose if you want the current user or type a usernameREM if you want to type a username
Set /p victem=Username?:REM if you want the current user
Set victem=%username%
REM get some information from the active directory
dsquery user -samid %victem%>c:\temp\dsquery.tmp
for /f “tokens=*” %%a in (‘type c:\temp\dsquery.tmp’) do set temp1=%%a
dsquery user %temp1% |dsget user -fn |find /v /i “fn “|find /v /i “dsget”>C:\temp\Fname.tmp
for /f “tokens=*” %%f in (‘type c:\temp\Fname.tmp’) do set temp-Fname=%%f
set Fname=%temp-Fname:~,-2%
dsquery user %temp1% |dsget user -ln |find /v /i “ln “|find /v /i “dsget”>C:\temp\Lname.tmp
for /f “tokens=*” %%l in (‘type c:\temp\Lname.tmp’) do set temp-Sname=%%l
set Sname=%temp-Sname:~,-2%REM clean up temp files
del c:\temp\dsquery.tmp
del C:\temp\Fname.tmp
del C:\temp\Lname.tmp
clsREM the result is stored in %Fname% for the First name and %Sname% for the surename
Echo Current target: “%Fname%” “%Sname%”
Leave a Reply