Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Setting AD attribute EmployeeType for all users

$
0
0

I am trying to set the employeeType attribute based on title for all users in the company.  If the title attribute contains the word "intern" the employeeType should be set to "Intern".  If the title attribute contains the word"contractor" the employeeType should be set to "Contractor".  All other non-blank titles should set the employeeType to "Employee".  The title is null for service accounts, admin accounts, test accounts, etc and the employeeType should be null also.

The PowerShell code below basically works, but it seems inefficient to process the whole AD three times.  Do you have suggestions on cleaning up the code?  Thanks.

Get-ADUser -Filter * -Properties * | ? {$_.title -Like '*intern*'} | Set-ADUser -Replace @{employeeType='Intern'}
Get-ADUser -Filter * -Properties * | ? {$_.title -Like '*contractor*'} | Set-ADUser -Replace @{employeeType='Contractor'}
Get-ADUser -Filter * -Properties * | ? {($_.title -ne $null) -and ($_.title -NotLike '*intern*') -and ($_.title -NotLike '*contractor*')} | Set-ADUser -Replace @{employeeType='Employee'}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>