AD Group Management Using Active directory PowerShell Module

Continuing with my Active Directory PowerShell Module series today I’ll show you how to manage Active Directory groups (single or multiple users).

In yesterday’s post I showed how to Manage Computers Using Active Directory Group Policy Module and today I’ll complement It with the ability to the same with Groups.

The most basic cmdlet In the module seen below will show you how to create an AD group (Global & Security) In a specific OU:

New-ADGroup "EX Team" -path 'OU=dev,DC=test,DC=local' -GroupScope Global -PassThru -Verbose

To create a Distribution group use:

New-ADGroup "DL EX Team" -path 'OU=dev,DC=test,DC=local' -GroupCategory Distribution -GroupScope Global -PassThru -Verbose

I can also use my magic CSV file to add and remove users as seen below:

To add users from a CSV file use:

Import-Csv .\users.csv | foreach {Add-ADGroupMember -Identity "EX Team" $_.user -Verbose -PassThru }

To remove users from a CSV file use.

Import-Csv .\users.csv | foreach {remove-ADGroupMember -Identity "EX Team" $_.user -Verbose -PassThru }

And I can also create a group based on Active Directory property like Department name:

Get-ADUser -Filter "department -eq '42'" | foreach {Add-ADGroupMember -Identity "EX Team" $_ -Verbose -PassThru }

To get Group Information:

Get-ADGroup "ex team"

To get group members use:

Get-ADGroupMember "ex team"

To count the number of Members In the group use:

Get-ADGroupMember "ex team" | measure