?
Solved

powershell script to add group member to other group from csv

Posted on 2016-09-02
6
Medium Priority
?
90 Views
Last Modified: 2016-09-02
hello,

i need a powershell script to add group member to other group from csv, the csv file is like this:

group,memberof
testgroup1,testgroup2
group1,group2;group3;group4

for the first exemple:
the script must add the group testgroup1 to membership of testgroup2

for the second exempe:
the script must add the group "group"1 to membership of the 3 group "group2;group3;group4"

thanks for help
0
Comment
Question by:cawasaki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 41781568
If I understand correctly you wan to add groups under group tab to respective groups under memberof column..

If yes try this..
Import-Module ActiveDirectory
Import-Csv C:\input.csv | %{
$Group = $_.Group
	$_.memberof -split "," | % {
		Add-ADGroupMember $_ $Group
	}
}

Open in new window


Sample input.csv file..
"Group","memberof"
"testgroup1","testgroup2"
"group1","group2,group3,group4"

Open in new window

0
 

Author Comment

by:cawasaki
ID: 41781673
hello Subsun,

your script work only for the frist group, in my exemple i can have one group that i need to add it to mant other group like my exemple: seperated bye ;

group,memberof
group1,group2;group3;group4


thanks
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41781677
Are you trying with the sample input file format which I gave in my answer comment?
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:cawasaki
ID: 41781694
yes, and it add only the first group not the all
0
 

Author Comment

by:cawasaki
ID: 41781699
oups its work very well sorry

thank you
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41781700
No problem.. :-)
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question