No announcement yet.

Where does AD get the %USERNAME% value from?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Where does AD get the %USERNAME% value from?

    Hi everyone, I'm a regular viewer of the Petri forum but this is my first post

    I was hoping some one could help me how to find in AD the value that sets the %USERNAME% variable for a user.

    for example; I have a number of users where the 'display name' shows as 'John Thomas' the 'User logon name:' shows as 'JohnT' but then the return value for the variable %USERNAME% when they are logged on is 'JThom12'

    This is important to me because the logon script for each user references %USERNAME% to map there personal drives.
    I need to clear down the folder which contains all these personal drives because they are littered with users that have left the company a long time back.

    So I've managed to pull out a list of 'currently employed' users from AD but I am struggling to match the username to their personal drives?
    Iím sure its in AD somewhere as doing a search using ADUC on the word 'JThom12' would bring up the user 'John Thomas', I then want to use the GUI or script to set the %USERNAME% value to same as the 'User logon name'

    Iíve painstakingly tried searching through the forums and googled to death but this is one of those questions which is proving a nightmare to search on because the key words are so common.
    Any help would be appreciated.

  • #2
    Re: Where does AD get the %USERNAME% value from?

    Got it!
    After dragging through the depths of ADSI I realised that the %USERNAME% is actually primarily populated from the 'alias' field in Exchange.

    Although there where some inconsistancies that threw me off track, which where derived from people changing there name in the past or bypassing the logon script with manual settings.

    Hope this helps someone sometime.


    • #3
      Re: Where does AD get the %USERNAME% value from?

      Thanks for the feedback MJBee.


      The %USERNAME% is the value of the sAMAccountName attribute from the userobject in AD.
      In ADUC this is the "User Name (pre-Windows 2000)" on the Account tab. This value must be unique in the domain. Also called the 'NT name' of the user.
      (or... if the object would be a computerobject, this accountname (w/out the trailing $) is sometimes called 'netbios name' and which is equal to the value of the %COMPUTERNAME% variable).

      "User Logon Name" in ADUC is the value of the userPrincipalName attribute. The user's name before the 'At sign' does not have to be the same as the value of the sAMAccountName attribute or any of the other name attributes of the user object.

      "Display name" in ADUC is the value of the displayName attribute.

      "Name" in ADUC is the Common name of the object, which is the value of the cn attribute. Which it is also part of the Distinguished Name.

      "Alias" on the Exchange General tab in ADUC is the value of the mailNickname attribute.


      This posting is provided "AS IS" with no warranties, and confers no rights.


      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts


      • #4
        Re: Where does AD get the %USERNAME% value from?

        Great stuff, thanks Rems, thats clears things completely.
        After making my 2nd post yesterday I went through and realised that I wasn't quite right.

        Thanks for the update, its been a great help.