Powershell Script to move an AD user account to another OU

Hi Everyone
I have been searching for this script a long while so if you are having the same problem here is the solution:
Given only a samaccount name/username, ths script will find the location of the user account and move it to the OU that you want:
# Given just the username/samaccountname (Andre), the location of the user object is found
# and the account is then moved to the NewOU
$UserName = "Andre"
# Finding the location of the user account Andre:
$Root = [ADSI]''
$searcher = new-object System.DirectoryServices.DirectorySearcher($root)
$searcher.filter = "(&(objectClass=user)(DisplayName= $UserName))"
$User = $searcher.findone()
# Binding the user account to $AUser and the OU to move to to $MovetoOU
$ADSPath = $User.Properties.adspath
$MoveToOU = [ADSI]("LDAP://OU=NewOU,DC=mydomain,DC=com")
$AUser = [ADSI]("$ADSPath")
# Command to Do the actual move
$AUser.PSBase.moveto($MoveToOU)
# Send me some comments.

I like a method like this...
Import-Module ActiveDirectory
get-aduser -filter {<What ever your search criteria is> } | %{move-ADObject $_.DistinguishedName -targetpath 'OU=NewOU,DC=Contoso,DC=Local'}
Works on Server 2008 R2 domain controllers, and RSAT tools on Windows 7 with SP1 when you have the AD powershell portion installed. Does not work with Server 2003 domain controllers or earlier.
I use that, but I don't care for having to type out the entire DN of the target OU if I'm working from the console.
I have this in my profile:
function Get-OU ($Name)
{ Get-ADOrganizationalUnit -filter "Name -like '*$Name*'" |
Out-GridView -OutputMode Single
So I can do this:
Import-Module ActiveDirectory
get-aduser -filter {<What ever your search criteria is> } |
%{ move-ADObject $_.DistinguishedName -targetpath (Get-OU Test).DistinguishedName }
And I'll get a grid view of all of the Test OUs, and I just pick the one I want from the gridview.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Similar Messages

  • Powershell Script to change the default user Account picture for all users in windows 7 and 8

    Hello,
    Can some sone help me with PS script to change user account pictures of all user account in windows 7 and windows 8 ?
    I will deploy this through MDT TS as Custom TS after OSD.
    Shailendra
    Shailendra Dev

    Hello,
    Can some sone help me with PS script to change user account pictures of all user account in windows 7 and windows 8 ?
    I will deploy this through MDT TS as Custom TS after OSD.
    Shailendra
    Shailendra Dev
    The default user account picture is stored here.
    C:\programdata\Microsoft\User Account Pictures\user.bmp
    It should just be a matter have copying the picture you want to that location and over writing what is there.
    or....
    Computer Configuration\Administrative Templates\Control Panel\User Accounts\Apply the default user logon picture to all users
    You can also configure this by a registry setting;
     [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer]
      UseDefaultTile = 1
    The picture that you configure, will not be loaded until the user account will actually be created on the pc. Meaning the first time a >new< user will log on to a pc, they will have no picture shown at all using their login screen (this is default
    behavior). Same will occur if you enable the policy don't display last user name. However, once they log in the picture will be shown in the start menu, and if they lock their pc the image will also be shown

  • In need of a Powershell script to move students from an OU to another OU

    Good Day Everyone,
    I was tasked to move students from the Students OU to Full Time / Part Time OU. I can possibly get this done in a short time BUT since I am a newbie, I would like to know what would be the best approach for me to get this done. 
    Details
    1. There are about 1700 students
    2. Import Students from an CSV file to be moved [fulltimestudents.csv AND parttimestudents.csv]
    3. After importing the students > move them to the fulltime or parttime OU
    Any suggestions before I start this and thank you all for your help.
    AM
    Adrian Mohamed

    Good Morning JRV + All,
    Here is a working code that I am now using for the move - any ideas on how to clean it up + maybe w/ comments would be much appreciated.
    remove-variable
    * -force
    Remove-Item
    -Path C:\temp\out.txt
    -Force
    $FULLTIMEOU='OU=Full
    Time,OU=Undergraduate,OU=Students,OU=Users,OU=LIM Objects,DC=limcollege,DC=edu'
    $PARTTIMEOU='OU=Part
    Time,OU=Undergraduate,OU=Students,OU=Users,OU=LIM Objects,DC=limcollege,DC=edu'
    clear
    # Import users from Carolyn’s CSV file [separate files for Full Time + Part Time]
    $user
    = ipcsv
    -path C:\temp\test2.csv
    # Get all students distinguished names > output them into a single file
    # Output to a txt gives us a paper trail of the actual students being moved
    foreach ($users
    in $user)
        (Get-ADUser
    $users.name).distinguishedname
    | Out-File
    C:\temp\out.txt -Append
    # Wait until the above transactions are complete
    Start-Sleep
    -s 2
    # Import the distinguished names > make the move to new OU
    $name
    = Get-Content
    -Path C:\temp\out.txt
    # Reiterate through the student names and perform the move
    foreach ($names
    in $name)
    Move-AdObject -Identity
    $names -TargetPath
    $FULLTIMEOU
    Adrian Mohamed

  • How do i transfer a rented movie from my user account to my wife's user account?

    How do I transfer a rented movie from my user account to my wife's user account?  I sync my iPad with my user account and she sync's her iPad with her user account, but she wants the movie I downloaded onto her iPad.  (We use the same apple ID).

    Using iPhone, iPad, or iPod with multiple computers - http://support.apple.com/kb/HT1202 - You can manage your iPhone, iPad, or iPod with multiple computers as long as you have set the device to "Manually manage music."  -  e.g. adding music from a second computer to an i-device.
    Hold on.  I don't know if the above will work with a rented movie.  There's all kinds of restrictions on what you can do with rented movies.
    How to move rented itunes movie from Imac to Ipad? - https://discussions.apple.com/message/17113392
    iTunes Store Movie Rental FAQ - http://support.apple.com/kb/HT1657

  • How do I transfer Pages from one user account to another

    How do you transfer Pages from one user account to another on the same Mac?

    Welcome to the Apple Support Communities
    If you haven't modified anything, Pages is installed on /Applications. All users have access to this folder, identified as "Applications" on the Finder sidebar, so you don't have to move anything, because Pages will work on all your users.
    If you have installed Pages on ~/Applications (being ~ your user folder), then you have to move Pages to /Applications. After doing this, you will be able to access to Pages on all users

  • Transfer music from one user account to another on the SAME mac?

    My family (wife, son, daughter, and me) share an imac but we all have our own user accounts. Our entire itunes music library is in one user account and is getting to the point of being unmanageable.
    Can I move some of my itunes library (e.g., my son's music) to another user account on the same iMac? Some songs were imported from CD and others were purchased from my Apple ID number.
    It's my understanding that an ipod can only be synced with one itunes library at a time, but I thought Apple also restricted the usage of music bought from itunes to a finite number of computers. If this is true, I think I would be able to transfer a group of songs from one user account to another so long as the user accounts were on the same computer.
    I was told that I could just drag the songs into a shared folder and then log into his account and drop them in iTunes.
    Some specific questions:
    1) Can I move all music files (CD and purchased) to the shared folder for dropping into his account?
    2)The purchased ones were purchased under MY apple ID which I do not want to give him access to. Should I create one for him or just have him use mine and wait for my password. I would like to put an allowance on his new ID number and keep it separate from mine. Would that make a difference in the future if I wanted to use one of his songs on my iPod or in an iMovie project?
    I just reinstalled my Lepoard OS X and put all my data back. I did not deauthorize anything before I did this. Did I need to? Or is even a clean install on the SAME machine ok and seen as the same authorization?
    Thanks in advance!!

    You can give him copies of song files, either by using a shared folder, or by putting the copies on a USB flash drive from which he can copy them to his own iTunes library.
    Any DRM-protected tracks that you have purchased from Apple can only be played if the user has authorization to the account(s) from which the tracks were purchased. Authorization requires physical access to the computer and knowledge of the password, and you can figure it from there!
    Message was edited by: ed2345

  • How to transfer all songs from a user account to another

    On the same Windows Vista computer, how to transfer / copy all music from one user account to another without using another computer or home sharing?
    (Please also consider that the iPad will also sync with the new user account without losing any songs.)
    Note: iTunes for Windows version 11.0.4.4

    Ivan H wrote:
    I guess I can change 2. to:
    Move or copy the iTunes folder from C:\Users\<User 1>\Music\iTunes to C:\Users\<User 2>\Music\iTunes, because I'll delete User 1 after done.
    Yes, that would work too.
    The iPad backups will not be transferred, am I right?
    Hmm, I think you are right. If I recall the backup exists in the user profile, so that would be the case.
    Is it sure that the iPad will be synced with User 2 without losing any songs?
    Yes, but to be safe, backup and sync the device with user 2 before deleting user 1.
    You should also maintain a separate backup.
    tt2

  • How to keep Itunes playing music when switching from one user account to another?

    On my old pc, that running XP, itunes would continue playing when I was switching from one user account to another.
    Now I have a new PC running win8 and the music stops playing when I switch from one user account to another. I think Itunes is still running on the user that is not active, but the music is not coming out of the speekers.
    Does anyone know how I can get the win8 pc to do as the old XP machine?

    Hello over here,
    The steps below detail how to place an input chooser that will allow for the adjustment of your keyboard layout while on the login screen.
    From the Apple menu, choose System Preferences.
    Click Users & Groups to display the pane (or choose User & Groups from the View menu).
    If the lock icon in the lower-left corner of the window is closed, click it, then enter the name and password of an administrator to unlock it.
    Click Login Options.
    Select the "Show Input menu in login window" checkbox.
    From the Apple menu, choose Log Out.
    At the login window, click the Input menu (shows the name of the currently selected input source next to a keyboard icon) in the upper-right corner of the screen, then select the desired input source or keyboard layout. If you don't see the input source you are looking for, move the pointer over Other Input Sources, then select the input source from the complete list that appears.
    OS X: How to change the keyboard layout at the login window
    http://support.apple.com/kb/HT4099
    Cheers,
    Allen

  • Can i move money from one account to another?

    Can i move money from one account to another?

    Basically, no; only the iTunes Store staff can do this, and then only by putting the balance from a completely unspent gift card back onto the card.
    (83942)

  • HT1373 how do I move songs form one account to another account?

    how do I move songs form one account to another account?

    Only sequentially. Each time you switch accounts, it will overwite the existing content with the new content.  As AnaMusic says, you cannot sync one device with two AppleID accounts at the same time, or even with the same AppleID on different computers for the same type of content (you could, for example, sync music to one computer, and calendars to a different computer, but not music to two different computers, even if they're the same AppleID). 
    Also, if you want to *re-download* content directly form the iTunes store (assuming it's an iPod Touch), you can only change IDs every 90 days.

  • How do I transfer files and documents from one user account to another?

    How do I transfer documents and files from one user account to another?

    You haven't understood me. Follow these steps:
    1. Log in the user where are the files you want to transfer, and open a Finder window.
    2. In Finder, select Go menu (on the menu bar) > Go to Folder, and type /Users/Shared. Now you're on Shared folder, so leave that window.
    3. Open a new Finder window without closing the old one, go to the folder with the files you want to transfer, and copy them to Shared folder.
    4. After copying the files to Shared folder, go to  > Log Out, and log in the other user.
    5. Repeat the step 2, and you will get access to the transferred files. Now, you can open them directly from this folder, or you can copy them to a folder on your user folder

  • How do I copy an address book from one user account to another?

    How do I copy an address book from one user account to another?

    You haven't understood me. Follow these steps:
    1. Log in the user where are the files you want to transfer, and open a Finder window.
    2. In Finder, select Go menu (on the menu bar) > Go to Folder, and type /Users/Shared. Now you're on Shared folder, so leave that window.
    3. Open a new Finder window without closing the old one, go to the folder with the files you want to transfer, and copy them to Shared folder.
    4. After copying the files to Shared folder, go to  > Log Out, and log in the other user.
    5. Repeat the step 2, and you will get access to the transferred files. Now, you can open them directly from this folder, or you can copy them to a folder on your user folder

  • Can I move music and movies from one icloud account to another icloud account?

    Can I move music and movies from one icloud account to another of my icloud accounts?

    No.  Purchased music, movies and other iTunes media is permanently tied to the Apple ID used to purchase it and can't be transferred to another ID.  (Your purchases are stored in iTunes in the Cloud under the Apple ID used to purchase them.)

  • Failure to move messages from one account to another

    I have recently started having problems when trying to move messages from one account to another. I get a message that says: The IMAP command "APPEND" (to INBOX) failed with server error: message contains NUL characters.
    I have tried shutting down and restarting, repaired permissions. Not sure what to do next. Any help?

    Ernie,
    One is POP thru Cox Comm and the other is mobile me (the old .mac accts). Why would all of a sudden there be an issue when I several times during the day have been able to move messages from Cox to mobile me?

  • Transfer Reports from one user account to another

    Hi,
    We use oracle discoverer 4.1, due to HIPAA the dba had to create new userids for our current users and lock the old ones, how do I transfer the reports stored in database one user account to another ?
    for e.g user abc123 has a report <abc.dis> stored in database he now has to use a new userid xyz123, he doesnt see <abc.dis>, how do I transfer this?
    I know the work around.. to save all reports from database to a network and open in the new user account, but we don't want users to do that, is there any other way?
    Thanks,
    Latha

    To avoid permission issues log into the account where the files are. Then transfer them to an external drive or a flash drive or jump drive. Then log into the account where you want them. Then copy them to the account.

Maybe you are looking for

  • ITunes doesn't launch; no error message, computer freezes up.

    When I click on my iTunes desktop icon, a message appears saying, "Please wait while Windows configures iTunes...". Then the computer slows to a crawl, and within minutes completely freezes up, fails to recognize key-strokes, or mouse movement and I

  • How do I change the admin name in the popup dialog

    I am giving my old MacBook (10.6.8) to my mother and for certain reasons I didn't want to wipe it clean but just clear out some of my stuff and transfer it to her.  Everything has been successful, including changing the User directory name from mine

  • Muse Website issue - I can't send direct page links to clients

    Hi all I would like to send my client a direct page link from my website so that they can view some photos I have taken for them.  The page is purposefully not listed on the site menu so that is has a low level of privacy. When I enter www.domain.com

  • Sync ical help

    is there a way I can sync my iCal to my gmail. I got gmail to sync to iCal. i just don't want to have to go online to update my calender.

  • Mac OSX lion

    We have two macs. We downloaded Lion on one successfully in September. We went to download Lion on the other Mac today. We seem to have downloaded the same copy on to the other Mac not a new copy. Is this a problem? It seems to be working fine ....