Filtering AD Object

Hey guys. I made a small script to pull all users and filter them with attribute ‘employeeType’ that equals ‘e’. Now i have a need to pull all that are ‘e’ and ‘c’, only. How do i accomplish this in my script, for different inputs to the ‘employeeType’ attribute?

Import-Module ActiveRolesManagementShell
Connect-QADService -Service OGBDARS01 -Proxy
Set-QADPSSnapinSettings -DefaultSizeLimit 0

Get-QADUser -Enabled -IncludedProperties employeeID -LdapFilter '(employeeType=e)' | Select-Object -Property samAccountName, Name, employeeID, employeeType |
    Export-Csv -Path .\Enabled_CORP_Employees.csv -NoTypeInformation

Since Powershell v3 you don’t need to import modules explicitly anymore. And you don’t need the Quest cmdlets anymore at all. The activedirectory module included in the RSAT tools are capable to fully replace them.

This should be all you need:

Get-ADUser -Filter 'Enabled -eq $True -and employeeType -eq "e" -or employeeType -eq "c"' -Properties employeeType, employeeID | 
Select-Object -Property samAccountName, Name, employeeID, employeeType |
Export-Csv -Path .\Enabled_CORP_Employees.csv -NoTypeInformation
1 Like

Thank you so much. this actually runs faster too…