0

I'm having SharePoint 2016 On-premise environment, now we have a requirement as follows.

we have nearly 100 SharePoint Groups, where we had already have many user's identity added as DOMAIN\username ,now we want to add their full Email ID username@company.com to connect the site with Azure AD. In other words, in each group we need to take a list of existing user IDs (DOMAIN\username)and add a new Identity( username@company.com )for each user in the same group.

Initially we started adding the IDs manually, but its time taking process.

can anyone please suggest a power shell script to complete this activity easily.

2
  • 1
    Is there a reason you're not using Move-SPUser? – Trevor Seward Jun 1 '20 at 4:24
  • @TrevorSeward, thanks for responding, we want to keep the existing identities also for sometime, and I'm not sure, move-spuser can solve this, can you please explain with a sample code or with an example – Jegan Baskaran Jun 1 '20 at 4:42
0

You might look into this script:

$newID = "%firstname:lower%.%lastname:lower%@example.com" # TODO: modify me

# Get the Microsoft 365 object ID
try
{
    $objectId = [GUID]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    $Context.LogMessage("The user doesn't have a Microsoft 365 account", "Warning")
    return
}

# Connect to Microsoft 365
$Credential = $Context.GetOffice365Credential()
Connect-MsolService -Credential $Credential

# Check whether the Microsoft 365 User ID differs from the new ID
$userM365 = Get-MsolUser -ObjectId $objectId
$m365Username = $userM365.UserPrincipalName

if ($m365Username -ieq $newID)
{
    return # No changes needed
}

# Change the Microsoft 365 User ID
Set-MsolUserPrincipalName -ObjectId $objectId -NewUserPrincipalName $newID
$Context.LogMessage("Microsoft 365 User ID has been changed to: $newID", "Information")

Reference:

Change user ID in Microsoft 365

1
  • thanks for replying, my site is an On-Premises environment what are changes need to be done in this script. – Jegan Baskaran Jun 1 '20 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.