Solved

powershell script to add group member to other group from csv

Posted on 2016-09-02
6
63 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
  • 3
  • 3
6 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

839 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