Update AD User from a CSV file and send them an email to notify about the change. This script will update the AD User with their new job title and send an email based on a template to notify them about the change.

A simple script that will check if the user exists in the AD and update it based on the CSV file. Sends an email to the user with the changed data. 

 

Read more about it here: https://lazyadmin.nl/powershell/using-powershell-to-update-an-ad-user-from-a-csv-file/

 

code snippet:

 

PowerShell
Edit|Remove
foreach($user in $promotions){ 
    #find user 
    $ADUser = Get-ADUser -Filter "displayname -eq '$($user.name)'" -Properties mail 
 
    if ($ADUser){ 
        Set-ADUser -Identity $ADUser -Title $user.jobtitle -WhatIf 
 
        $emailBody = Get-EmailTemplate -user $ADUser -JobTitle $user.jobtitle 
        Send-Mail -user $ADUser -EmailBody $emailBody -whatIf $true 
    }else{ 
        Write-Warning ("Failed to update " + $($user.name)) 
    } 
}