Re: Get Username from Full Name?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jerold Schulman (Jerry_at_jsiinc.com)
Date: 06/02/04


Date: Wed, 02 Jun 2004 11:58:07 -0400

On Wed, 2 Jun 2004 07:56:08 -0700, Mike C <anonymous@discussions.microsoft.com>
wrote:

>Hi Everybody,
>
>I'm sure that there has to be a way to script this, but I haven't been able to Google anything. We have a Windows 2000 domain with several hundred users. Currently, there are two different username standards in practice. One is first initial + last name, the other is the first 4 letters of the last name + first two initials of first name + 1. I would like to write a script that, given the user's full name, can pull out the current userid. I have scripts that work the opposite way (given userid, find full name), but I can't seem to modify them to do what I would like. Can anybody help me out or point me to a website that describes how to do this?
>
>Thanks

Using tip 7714 in the 'Tips & Tricks' at http://www.jsiinc.com

FullName.bat (below) displays the userid on the console.
if you needed it in a variable, then
for /f "Tokens=*" %%u in ('Fullname "The Full Name"') do
 set variable=%%u
)

I assumed that Full Name was displayName. If not, you can adjust.

@echo off
if {%1}=={} @echo Syntax FullName "Full Name"&goto :EOF
setlocal
set fn=%1
set fn=%fn:"=%
set qry=dsquery * domainroot -filter
"(&(objectCategory=Person)(objectClass=User)(displayName=%fn%))" -attr
sAMAccountName -limit 0
REM The above 3 lines are 1 line
for /f "Skip=1 Tokens=*" %%a in ('%qry%') do (
 @echo %%a
)
endlocal

Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com



Relevant Pages

  • Re: Console Logon timeout?
    ... It would be nice to be able to associate a "default" SAF userid with consoles that have not yet logged on. ... I was asking for a default SAF UTOKEN to be supplied when a console is not logged on. ... When I was playing around with this, I noticed that commands issued from LOGONconsoles without an associated userid would get security failures for a user called '+CONSOLE'. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: Console Logon timeout?
    ... consoles, when the console becomes active, it is signed on under a UserID ... Subject: Console Logon timeout? ... Search the archives at http://bama.ua.edu/archives/ibm-main.html ...
    (bit.listserv.ibm-main)
  • Unable to run external program exes
    ... The console app ... I use another userid (which is not an admin), ... I am running this console app. ...
    (microsoft.public.dotnet.security)
  • Unable to run external program exes
    ... The console app ... I use another userid (which is not an admin), ... I am running this console app. ...
    (microsoft.public.dotnet.security)
  • How to change the console name as logon ID name after logon to console
    ... I try to logon to existing console with other userid name but the console ... message JOBNAME still show up the console ID instead of new userid. ...
    (bit.listserv.ibm-main)