Friday, February 20, 2015

How to Create Multiple AD Group in PowerShell Script

#;
  

Date: 20-Feb-2015 ; 11:37AM
Author: Ashish Kumar Jha
Email: aashujha@gmail.com
blog:
http://ajhaexchange.blogspot.in/

#

#Notes

# make sure you have RSAT Tool Installed
# Make Sure you imported Active Directory Module before running this command


# Global Variables

# OU Path of the Group in which we want to create groups
$path = "OU=testing,DC=techmesupport,DC=in"


# Domain Admin Credentails
$cre = get-Credential
 

#Main Server
$srvr = "DC-LAB"


# username is domain users "SAM Account " name , use Get-AdUser to find our SAM name of the user.
$usr = "aashujha"


#Dfine Group which need to be created
$grpname = "Test1","Test2"

# Lets use ForEach patters to create the group


foreach ($group in $grpname) {
$name = $group
 

# Just a console message
write-Host -ForegroundColor Magenta "Grouname is $name."


# Using AD Module
New-ADGroup -Path $path -Name $name -GroupCategory Security -GroupScope Global -Server $srvr -Credential $cre


# Just a console message
Write-Host -ForegroundColor Yellow "Group $name Created, let me add users in to this group."


# Using AD Module
Add-ADGroupMember $name $usr -Server $srvr
 

# Just a console message
Write-Host -ForegroundColor Green "Member are added to the group $name ."


####Everything Should be done by now ###


}

### End of the Script#### | A S H I S H | J H A | 


No comments:

Post a Comment