Home » PowerShell » Get AdUser Pipe to Add AdGroupMember

Get AdUser Pipe to Add AdGroupMember

To get aduser pipe to add into the active directory group as a member, you will need to get aduser using the Get-AdUser and pipe them to the Add-AdGroupMember cmdlet.

The Get-AdUser cmdlet in PowerShell gets one or more active directory users and the Add-AdGroupMember cmdlet adds one or more users to the active directory group.

In this article, we will discuss how to output the Get-Adduser pipe the Add-AdGroupMember command to add to the active directory group.

Get-AdUser Pipe to Add-AdGroupMember

Use the Get-AdUser cmdlet with the Identity parameter to specify the user and get the aduser object. It pipes the aduser to Add-AdGroupMember to add to the ad group specified.

Note here, that the Get-AdUser pipe to Add-AdGroupMember works with a foreach loop on the Add-Add-AdGroupMember cmdlet.

# Get AdUser pipe to Add-AdGroupMember
Get-AdUser -Identity gary.waugh | % {Add-ADGroupMember SALESLeader $_}

# Get aduser groups

(Get-ADUser -Identity gary.waugh -Properties MemberOf).MemberOf | Get-AdGroup | Select-Object Name

In the above PowerShell script, the Get-AdUser cmdlet uses the Identity parameter to specify the aduser and pipe the aduser to the foreach loop where it has the Add-AdGroupMember cmdlet to add the user to an ad group.

The output of the above script adds aduser “Gary Waugh” to the ad group SALESLeader.

To get aduser groups in PowerShell, the Get-AdUser uses the Identity parameter to specify the aduser for which we want to get aduser group and display the ad group name.

The output of the above PowerShell script to get aduser pipe to Add-AdGroupMember and get aduser group is:

Get AdUser pipe to Add-AdGroupMember

Conclusion

I hope the above article on how to get aduser pipe to add adgroupmember is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.