1

I want to update a set of AD users with a nested powershell command and I need help with that :(

  1. Get all users with a specific attribute (Get-ADUser -Filter 'extensionAttribute1 -like "*"')
  2. Add this users to a specific group (Add-ADGroupMember -Identity "GroupNAME" -Member USERNAME)
  3. Delete the extension attribute (Set-ADUser –Identity USERNAME -Clear "extensionattribute1")

Thanks for your help!

2
  • What have you tried so far? Commented Dec 17, 2018 at 10:46
  • You can see my commands in the (). Problem is I don't know how to nest this. Commented Dec 17, 2018 at 10:49

1 Answer 1

2

Have a look at how to use a result set within a foreach loop like this:

Get-ADUser -Filter 'extensionAttribute1 -like "*"' | foreach {

    Add-ADGroupMember -Identity "GroupNAME" -Members $_.samaccountname
    Set-ADUser –Identity $_.samaccountname -Clear "extensionattribute1"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.