Re: Get Username from Full Name?
From: Jerold Schulman (Jerry_at_jsiinc.com)
Date: 06/02/04
- Next message: Tommy Vercetti: "Moving from Mixed to Native Mode."
- Previous message: Joe Kania: "LDAP Event driven updates"
- In reply to: Mike C: "Get Username from Full Name?"
- Next in thread: Mike C: "Re: Get Username from Full Name?"
- Reply: Mike C: "Re: Get Username from Full Name?"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Tommy Vercetti: "Moving from Mixed to Native Mode."
- Previous message: Joe Kania: "LDAP Event driven updates"
- In reply to: Mike C: "Get Username from Full Name?"
- Next in thread: Mike C: "Re: Get Username from Full Name?"
- Reply: Mike C: "Re: Get Username from Full Name?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|