Here are some scripts for group editing. I sourced from internet, Start with Basics then put them together.
1.  Add security group:

New-ADGroup -Name "RODC Admins" -SamAccountName RODCAdmins -GroupCategory Security -GroupScope Global -DisplayName "RODC Administrators" -Path "CN=Users,DC=Fabrikam,DC=Com" -Description "Members of this group are RODC Administrators"  
Get-ADGroup FabrikamBranch1 -Properties Description | New-ADGroup  -Name Branch1Employees  -SamAccountName Branch1Employees -GroupCategory Distribution -PassThru                            

Details: http://technet.microsoft.com/en-us/library/ee617258.aspx

2. Add DistributionGroup

$OU = Get-QADObject "ou=groups,ou=NameOfOU,dc=NameOfDomain"
New-DistributionGroup -Name "Managers" -OrganizationalUnit $OU -SamAccountName "Managers" -Type "Security"

Details:
http://technet.microsoft.com/en-us/library/aa998856(v=exchg.150).aspx

3. Add group members to a group:

Import-module ActiveDirectory 
$userlist1 = import-csv xxxx.csv  -header ID,Group
Foreach ($user in $userlist1)
{ 
Add-ADGroupMember -Identity $user.Group -Member $user.ID -erroraction 'silentlycontinue' which 
} 

4. List group members:

get-distributionGroupMember $GroupName | foreach-object {echo $_.name}

5. List all distribution Groups:

get-distributionGroup

6. A good example from http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Bulk-AD-Group-4d873f35

########################################################### 
# AUTHOR  : Marius / Hican - http://www.hican.nl - @hicannl  
# DATE    : 08-08-2012
# EDIT    : 16-11-2012
# CHANGES : Added functionality for duplicate OU names and
#           changed the input file slightly because of this
# COMMENT : This script does a bulk creation of Groups in
#           Active Directory based on an input csv and the
#           Active Directory Module. 
########################################################### 
Import-Module ActiveDirectory
#Import CSV
$csv = @()
$csv = Import-Csv -Path "C:\Temp\bulk_input.csv"
#Get Domain Base
$searchbase = Get-ADDomain | ForEach {  $_.DistinguishedName }
#Loop through all items in the CSV
ForEach ($item In $csv)
{
  #Check if the OU exists
  $check = [ADSI]::Exists("LDAP://$($item.GroupLocation),$($searchbase)")
  
  If ($check -eq $True)
  {
    Try
    {
      #Check if the Group already exists
      $exists = Get-ADGroup $item.GroupName
      Write-Host "Group $($item.GroupName) alread exists! Group creation skipped!"
    }
    Catch
    {
      #Create the group if it doesn't exist
      $create = New-ADGroup -Name $item.GroupName -GroupScope $item.GroupType -Path ($($item.GroupLocation)+","+$($searchbase))
      Write-Host "Group $($item.GroupName) created!"
    }
  }
  Else
  {
    Write-Host "Target OU can't be found! Group creation skipped!"
  }
}

 

 7. Enable mail for security group:

Enable-DistributionGroup -Identity "Server Lab 222"

 8. Delete all group members from one group

get-adGroupMember groupName | foreach-object {remove-adgroumember -Identity groupName -Member $_.distinguishedname -confirm:$false}

 

About Lei

I am an IT specialist with over 10 year experience - years on Automation, on-Premise or Azure.

I am happy to develop however never want be a full time developer. Only do what I have to do. If it has to be PowerShell,HTML, PHP, CSS, C#, VBS or JS, front end or backend, so be it, doesn't matter!

Spent years with Windows, SCCM, SharePoint, SQL and Exchange servers. For last several years, I have been actively working under On Premise > Azure environment.

THERE IS NO WAY BACK!!!

Current Certificates:
    Microsoft® Certified-
  • -Enterprise Administrator
  • -Database Administrator
  • -SharePoint Administrator
  • -Administering and Deploying SCCM 2012
Red Hat Certified Technician
ITIL V3 Foundation - Practitioner

Working on Azure Certificates now and hopefully they can stop upgrading their questions one day! GIVE ME A BREAK!

Contact Lei

Name *
Email *
Comments *

Traffic since 10/08/2016

Today48
Yesterday83
This week672
This month1968
Total416328

Visitor Info

  • IP: 54.227.51.103
  • Browser: Unknown
  • Browser Version:
  • Operating System: Unknown

Who Is Online

1
Online

2017-12-17

Login