Link to home
Start Free TrialLog in
Avatar of Isaias Perez
Isaias PerezFlag for United States of America

asked on

Powershell- Get-ADUser specific Attribute with Filter

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.
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Isaias Perez

ASKER

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}