Run PowerShell Script to Map ID
clear
#CSV File
$users= Import-Csv "C:\Users\Desktop\ScriptInput\users.csv"
#Connect to O365
Import-Module ActiveDirectory
#Connect to O365
Import-Module MSOnline
$UserName = "aadmin@ajewoleakingbadegmail.onmicrosoft.com"
#Use secure string for automation, do not use plain text password.
#$password = Get-Content "C:\SecureStrings\PasswordAkin.txt" | ConvertTo-SecureString
$password = ConvertTo-SecureString -String "PASSWORDTENANT" -AsPlainText -Force
$credential = new-object -typename system.management.automation.pscredential -argumentlist $UserName, $password
Write-Host "Running the script to Connect to Office365"
Connect-MsolService -Credential $credential
Write-Host "Completed running the script to Office365 - Run the cmdlet - Get-MSOLUser - to test connection"
$date = get-date
foreach ($user in $users) {
$user = $user.userprincipalname
$ErrorActionPreference = 'stop'
##AD User
##Cloud User
Get-MsolUser -UserPrincipalName $user | fl DisplayName, ObjectID, ImmutableID, UserprincipalName
$ID= [system.convert]::ToBase64String((Get-ADUser -filter {userprincipalname -eq $user}).objectGUid.ToByteArray())
Set-MsolUser -UserPrincipalName $user -ImmutableId $ID
##Cloud User
Get-MsolUser -UserPrincipalName $user | fl DisplayName, ObjectID, ImmutableID, UserprincipalName
}
CSV File Format
userprincipalname
username
username