22 lines
830 B
PowerShell
22 lines
830 B
PowerShell
|
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
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|