Creating a naming convention for local user profile name when singing in with a M365 user

PKU 0 Reputation points
2024-04-30T08:33:49.85+00:00

Hello,

as far as I'm aware, the name used for the local user profile when logging in to an Entra ID joined device for the first time is the first 20 letters of the M365 display name with special characters and spaces removed. We would like to keep the display names as it, but instead use an abbreviation for the name of the local user profile.

Example: When the display name in M365 is "Alex Wilber | Company A" we would like to have "AWI" as the name of the local user profile instead of "AlexWilberCompanyA".

We also would like this to be an automatic process more or less. Is there any reasonable way to archive this?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,986 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Navya 4,860 Reputation points Microsoft Vendor
    2024-05-02T06:11:37.0533333+00:00

    Hi @PKU

    Thank you for posting this in Microsoft Q&A.

    I understand you want to Create a naming convention for local user profile name when singing in with a M365 user.

    You can use PowerShell to automate this process.

    Install-Module -Name AzureAD
    Import-Module -Name AzureAD
    
    Connect-AzureAD
    $userid = "replace user object Id"
    $userdetails = Get-AzureADUser -ObjectId $userid 
    $displayName = $userid.displayname
    $firstName = ($displayName -split '\s+')[0]
    $lastName = ($displayName -split '\s+')[1]
    $companyName = ($displayName -split '\s+\|\s+')[1]
    $abbreviation = $firstName.Substring(0,1) + $lastName.Substring(0,1) + $companyName.Substring(0,1)
    Set-AzureADUser -ObjectId $userid  -DisplayName $abbreviation
    

    To update bulk users, create a CSV file as userIDs.csv with UserID

    $userIDs = Import-Csv -Path "userIDs.csv" | Select-Object -ExpandProperty UserID
    
    foreach ($userID in $userIDs) {
        # Retrieve user details
        $userDetails = Get-AzureADUser -ObjectId $userID
        
        $displayName = $userDetails.DisplayName
        $firstName = ($displayName -split '\s+')[0]
        $lastName = ($displayName -split '\s+')[1]
        $companyName = ($displayName -split '\s+\|\s+')[1]
        
        $abbreviation = $firstName.Substring(0,1) + $lastName.Substring(0,1) + $companyName.Substring(0,1)
        # Set new DisplayName
        Set-AzureADUser -ObjectId $userID -DisplayName $abbreviation
    }
    

    Hope this helps. Do let us know if you any further queries.

    Thanks,

    Navya.

    1 person found this answer helpful.