Canonical name (CN) instead of Username

How can I change this logon script to show the canonical name (i.e. John Smith) instead of %USERNAME% -  using windows 2003 standard, thanks.

@echo %DATE% - Logon From: %COMPUTERNAME%,

 User Name: -----> %USERNAME%, LogonTime: %TIME%  >>

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Malli BoppeCommented:
I don't think you can do it through a batch script you need to write a VB script.
Farhan KaziSystems EngineerCommented:
Try if this works for you!

NET USER "%USERNAME%" /DOMAIN |FIND /I "Full Name"  >>\\SERVER\Monitoring$\%username%.log

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tracymsAuthor Commented:
Thanks farhankazi,

You were close and pointed me in the right direction, I got it working with the following:

for /f "Tokens=2*" %%m in ('net user %USERNAME% /domain ^| find "Full Name"' ) do set fname=%%n
@echo %DATE% - Logoff From: %COMPUTERNAME%, User Name: %fname%, Logoff Time: %TIME%  >> \\SERVER\Monitoring$\%username%.log
In order for this script to display the first and last name of the domain user, you need to add their first and last name to "Display Name" in the user's properties in Active Directory - under the General tab.

tracymsAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.