Update Group Members from CSV

Hi All,

Today I am sharing my old script that I had used for updating the group members from CSV file.

I was performing the same activity today so thought of sharing it.

You just have to Prepare CSV as below:-

 

after that just define group name inside the script.

#############################

$grp =

##############################

This script requires quest management shell.

http://www.quest.com/powershell/activeroles-server.aspx

Execute script as below:

below is the link to the zip file along with script & example csv

http://gallery.technet.microsoft.com/scriptcenter/Update-Group-Members-from-46e27c78

Script Code:-

########################################################################################### 
##                                                                                             
##           Author: Vikas Sukhija                                                         
##           Date: 26-11-2012                                                        
##           Description:- If user is not a member of group this script add it after reading    
##           from CSV                                                                                
########################################################################################### 
#Add Quest Shell... 

If ((Get-PSSnapin | where {$_.Name -match "Quest.ActiveRoles"}) -eq $null) 
{ 
    Add-PSSnapin Quest.ActiveRoles.ADManagement 
} 

#####define Group######## 

$grp="Group Name" 

######################### 

# import csv file 

$data = import-csv $args[0] 

$Can = “CN=$grp” 

Write-host $Can 

#Check if usr belogs to group in csv 

foreach ($i in $data) 

{ 

$user=get-qaduser $i.userid 

  if (($user.memberof -like “$Can,*”)) 

  { 

  write-host “$user is a member & will not be added to $grp group” 

  } 

  else 

  { 

  write-host “$user is not a member & will be added to $grp group” 

  add-qadgroupmember $grp $user   

  } 

} 
########################################################################################

 

Regards

Sukhija Vikas

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s