Solved

powershell script to add group member to other group from csv

Posted on 2016-09-02
6
42 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
Comment Utility
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
Comment Utility
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
Comment Utility
Are you trying with the sample input file format which I gave in my answer comment?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:cawasaki
Comment Utility
yes, and it add only the first group not the all
0
 

Author Comment

by:cawasaki
Comment Utility
oups its work very well sorry

thank you
0
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
No problem.. :-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now