Solved

powershell script to add group member to other group from csv

Posted on 2016-09-02
6
58 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

777 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