Soft vs hard matching et script

 

https://www.itpromentor.com/soft-vs-hard-match/

verifier les parametres AD
Get-ADUser -SearchBase “DC=company,DC=local” -Filter * -Properties * | Select-Object -Property Name,SamAccountName,EmailAddress | Sort-Object -Property Name | Export-Csv -path C:\export\ADUsers.csv

sur office 365
Get-MsolUser | select-object -property userprincipalname,displayname,islicensed | export-csv -path c:\export\365Users.csv

Verifier que upn et adresse mails correspondent puis syncroniser sur AD

Hard Match problem (ex probleme si upn local ne correpond pas a upn@contoso.com)
$credential = Get-Credential
Connect-MsolService -Credential $credential
$ADUser = "username" 
$365User = "username@emaildomainname.com"
$guid =(Get-ADUser $ADUser).Objectguid
$immutableID=[system.convert]::ToBase64String($guid.tobytearray())
Set-MsolUser -UserPrincipalName "$365User" -ImmutableId $immutableID

avec un csv, on cree un script match.ps1

Param(
$username
)
$365User="$username@emaildomainname.com"
$guid=(get-ADUser $username).Objectguid
$immutableID=[system.convert]::ToBase64String($guid.tobytearray())
Set-MsolUser -UserPrincipalName "$365User" -ImmutableId $immutableID

Lancer le script avec fichier csv

Connect-MsolService
Import-Csv -Path C:\scripts\users.csv | ForEach { C:\scripts\HardMatch.ps1 -Username $_.Username }