Need Help in Moving Bulk Group from OU to its Parent OU.

  • 1.4K Views
  • Last Post 11 February 2016
syam posted this 10 February 2016

Hello Everyone!!
I have an urgent task at hand to move a large number of groups from one OU to its child OU. This is the script I am trying to use, but it doesn't do anything, its just jumping to next prompt. 
The group name format I've given in C:\Users.csv is "cn=group1,ou=test location,dc=testna,dc=testds,dc=monsanto,dc=com"
Any help is greatly appreciated.
# Specify target OU.$TargetOU = "ou=ChildOU,ou=test location,dc=MyDomain,dc=com"
# Read user sAMAccountNames from csv file (field labeled "Name").Import-Csv -Path C:\Users.csv | ForEach-Object {    # Retrieve DN of User.    $UserDN = (Get-ADUser -Identity $_.Name).distinguishedName
    # Move user to target OU.    Move-ADObject -Identity $UserDN -TargetPath $TargetOU}
Thanks in advance,Syam.

Order By: Standard | Newest | Votes
CrawfordS posted this 10 February 2016

Can you post a sample of Users.csv?

 

Also, your post seems a little confused. The subject says you want to move groups to their parent. But, in the message, you want to move them

to a child OU. And, I’m confused where users enter the picture. Are you trying to move members of a group to a certain OU?

 

show

syam posted this 11 February 2016

Hi Scott,
Thanks for the reply and sorry for the confusion :) Your mail was an eye opener. 
I am a newbie in powershell scripting. My goal is to move bulk groups from parent OU to its child OU. After going through your reply i checked the script and i can see i am using Get-ADUser instead of Get-ADGroup. Even after making changes it didn't work, without giving any error message it jumps to the next command prompt. The whole script along with the input csv file is give below. 
Here is an example of Groups.csv file. I have changed the csv file name to avoid confusion. 
           "cn=group1,ou=test location,dc=MyDomain,dc=com"
           "cn=group2,ou=test location,dc=MyDomain,dc=com"
This is the script.
           # Specify target OU.           $TargetOU = "ou=ChildOU,ou=test location,dc=MyDomain,dc=com"
           # Read group sAMAccountNames from csv file (field labeled "Name").
           Import-Csv -Path c:\Group.csv | ForEach-Object {           # Retrieve DN of group.           $GroupDN = (Get-ADGroup -Identity $.Name).distinguishedName
           # Move group to target OU.           Move-ADObject -Identity $GroupDN -TargetPath $TargetOU            }
Thanks in advance,Syam


show

jarves posted this 11 February 2016

Why not try to use DSMOD?


show

CrawfordS posted this 11 February 2016

Thanks for the clarification. It looks good and tested fine for me. A couple things to check – Does your CSV file have a header on the first line? It should just

be the word Name since that’s the property you’re looking for. If it’s not practical to add a header row, you can specify a header on your Import-CSV line:

 

Import-Csv

-Path c:\Group.csv

-Header "Name"

 

Also, your comment on the script indicates that you’re looking for sAMAccountName. However, the example lines from the CSV are distinguishedNamed. So, you could

skip the line that gets the group and then reads the distinguished name and jump straight to the Move-ADObject line.

 

See how this looks:

 

# Specify target OU.

$TargetOU

= "ou=ChildOU,ou=test location,dc=MyDomain,dc=com"

 

# Read group DNs from csv file without header row.

Import-Csv

-Path c:\Group.csv

-Header "Name"

| ForEach-Object {

 

   

# Move group to target OU.

   

Move-ADObject -Identity

$.Name

-TargetPath $TargetOU

}



 

 

 

show

syam posted this 11 February 2016

Hi Scott,
It worked like a charm!! Thanks a ton. You saved my day. As you mentioned I have added a header in the csv file and it was ready to go. 
I really appreciate your efforts :)
Thanks Again,Syam. 


show

CrawfordS posted this 11 February 2016

Cool. Glad to help.

 

show

Close