Powershell- Get-ADUser specific Attribute with Filter

Isaias Perez
Isaias Perez used Ask the Experts™
on
I am trying to put together a PS script that will search my entire user database and find all users who's description match this exactly "ACCTMGR - Account Manager" but filter out all Users who's Enabled Property is True. In other words only search users who are active and not disabled.

I have tried the following script but something is wrong with it. Can anyone help me fix it please.
Get-ADUser -Filter {description -like 'ACCTMGR - Account Manager'} | Where-Object {$_.Enabled -eq True}

Open in new window


Then ultimately i want to take all of these users "Account Managers" and add them a Distribution List
Account_Managers_All.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
This should be correct.
Get-ADUser -Filter {description -eq 'ACCTMGR - Account Manager' -and Enabled -eq $True}

Open in new window

The only problem I saw with your code was the use of "True" instead of "$true".
Top Expert 2014

Commented:
To add to a group.
$users = Get-ADUser -Filter {description -eq 'ACCTMGR - Account Manager' -and Enabled -eq $True}
Add-ADGroupMember -Identity "somegroup" -Members $users

Open in new window

Isaias PerezIT Operations Manager

Author

Commented:
Thank you very much. Figured out the rest of the code to add those users to a Security Group:

Import-CSV C:\all_directorofops.csv -Header SamAccountName | ForEach-Object {Add-AdGroupMember -Identity "Powerbi_All_Directors" -members $_.SamAccountName}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial