PowerShell 7.3 - implementing Filtering Active Directory Users by Multiple Attributes
I'm writing unit tests and I'm having a hard time understanding I'm trying to debug I'm trying to filter users in Active Directory using PowerShell 7.3, but I'm running into issues when trying to filter by multiple attributes... Specifically, I want to retrieve all users whose `Department` is 'Sales' and `Title` is 'Manager'. I have tried using the `Get-ADUser` cmdlet with the `-Filter` parameter, but it seems that my syntax is incorrect. The following command: ```powershell Get-ADUser -Filter "Department -eq 'Sales' -and Title -eq 'Manager'" -Property Department, Title ``` throws an behavior stating `Get-ADUser : The 'Filter' parameter must be a valid LDAP filter string`. I realize that my filter may not be structured correctly for what PowerShell expects. I also experimented with creating a more complex filter using a script block: ```powershell Get-ADUser -Filter { Department -eq 'Sales' -and Title -eq 'Manager' } -Property Department, Title ``` However, this returns an empty result set despite there being users that meet the criteria. I've confirmed that the `Department` and `Title` attributes do exist and contain the correct values by running: ```powershell Get-ADUser -Filter * -Property Department, Title | Select-Object Department, Title ``` Could someone point me in the right direction regarding how to structure the filter correctly or suggest an alternative method to achieve this? Any help would be greatly appreciated! I'm using Powershell 3.9 in this project. Thanks for taking the time to read this! This issue appeared after updating to Powershell 3.9. What would be the recommended way to handle this?