• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 104
  • Last Modified:

powershell script to add group member to other group from csv

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
cawasaki
Asked:
cawasaki
  • 3
  • 3
1 Solution
 
SubsunCommented:
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
 
cawasakiAuthor Commented:
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
 
SubsunCommented:
Are you trying with the sample input file format which I gave in my answer comment?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
cawasakiAuthor Commented:
yes, and it add only the first group not the all
0
 
cawasakiAuthor Commented:
oups its work very well sorry

thank you
0
 
SubsunCommented:
No problem.. :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now