ADScripts/Update-ADTitles.ps1

22 lines
830 B
PowerShell
Raw Normal View History

2023-09-14 11:13:58 -06:00
if (!($cred)) {
$cred = Get-Credential -Message "Enter your Domain Admin credentials"
}
## Check for Blank Titles
$CompanyTitles = Import-Csv '.\AD Scripts\CSV\JobTitles.csv'
$MissingTitles = Get-ADUser -Filter '(mail -like "*mpe.ca")' -Properties mail,title,office | where-object title -eq $null | `
where name -NotMatch 'Mailbox|Migration|Federated|Boardroom|Presentation|Survey|Conferences' | select surname, GivenName, name, mail, title,samaccountname
foreach ($user in $MissingTitles) {
$newTitle = $CompanyTitles | where 'Last Name' -eq $user.surname | where 'First Name' -eq $user.GivenName | select Title
if ($newTitle) {
Write-host 'Setting ' $user.name ' to ' $newTitle.Title
Set-ADUser -Title $newTitle.Title -Credential $cred -Identity $user.samaccountname
}
}