Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

First time using PowerShell and could use some help.

$
0
0

I'm trying to come up with a script that will allow me to, in bulk, do the following:

1. Move a user from one OU to another

2. Remove two groups from the user

3. Add two groups to the user

 

So far this is what I've come up with...

 

CSV constructed like below...

DN                                                                                                                                                   
“CN=John R, OU=BB,OU=ES,OU=Students,OU=OSD,DC=usd233,=DC=local”                     

TargetOU

"OU=PRT,OU=MS,OU=Students,OU=OSD,DC=usd233,DC=local"

 

Import-Module activedirectory

$UserList = Import-Csv "c:\yourCSVhere.csv"

foreach ($User in $UserList) {

$User.DN

$User.TargetOU

Move-ADObject -Identity $User.DN -TargetPath $User.TargetOU

Remove-ADGroupMember -Identity _ElemStudents -Member $User.DN

Remove-ADGroupMember -Identity BBStudents -Member $User.DN

Add-ADGroupMember -Identity _MSStudents -Member $User.DN

Add-ADGroupMember -Identity _PRTMS_Students -Member $User.DN

 

}

 

Would this script accomplish what I'm trying to do? Or am I missing some information either in the script or the csv? Any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 6937

Trending Articles