Bulk Move Users and Computers in Active Directory with PowerShell

preview_player
Показать описание
Learn how to bulk move users and computer in Active Directory with Powershell.

You can use the get-aduser and get-adcomputer PowerShell commands to find accounts then pipe them to the move-adobject command.

Command and scripts are below:

Example 1: Move single user

Get-ADUser -Identity username | Move-ADObject -TargetPath "OU=Accounting,OU=ADPRO Users,DC=ad,DC=activedirectorypro,DC=com"

Example 2: Move all users from one OU to another OU

Get-ADUser -filter * -SearchBase "OU=Accounting,OU=ADPRO Users,DC=ad,DC=activedirectorypro,DC=com" | Move-ADObject -TargetPath "OU=Accounting-2,OU=ADPRO Users,DC=ad,DC=activedirectorypro,DC=com"

Example 3: Filter for specific users and move to an OU

In this example I'm finding all users that have "Marketing" set for the department field

get-aduser -filter {department -eq 'Marketing'} | move-adobject -targetpath "OU=Marketing-2,OU=ADPRO Users,DC=ad,DC=activedirectorypro,DC=com"

Example 4: Moving users from a CSV file

# Import the data from CSV file and assign it to variable

# Specify target OU where the users will be moved to
$TargetOU = "OU=Accounting,OU=ADPRO Users,DC=ad,DC=activedirectorypro,DC=com"

$Import_csv | ForEach-Object {

# Retrieve DN of User
$UserDN = (Get-ADUser -Identity $_.SamAccountName).distinguishedName

Write-Host "Moving Accounts....."

# Move user to target OU. Remove the -WhatIf parameter after you tested.
Move-ADObject -Identity $UserDN -TargetPath $TargetOU
}
Write-Host "Completed move"

Additional Notes:
1. The move-adobject -targetpath requires the distinguishedName of the OU
2. To move computer accounts use get-adcomputer instead of get-aduser
3. The csv file needs a column header. If you change it make sure to update the script to match the column.

More Active Directory tutorials, scripts and tools.

Export users to CSV GUI Tool
Рекомендации по теме
Комментарии
Автор

Superb information, so so important and helpful, waiting for all kinds of technical troubleshooting videos related to Windows Server Migration, Active Directory Networking troubleshooting, Domain issues etc etc

supriyochatterjee
Автор

Hi Whats the easiest way to track which security group should I add for a network drive, our active directory setup does not tell much. please help.

tojix
Автор

what about for moving bulk AD groups to different OU?

kidschannel
Автор

Great video I am running into an error and I'm not sure if I did something wrong It says I don't have permission to move-adobject but if I can do it manually in the GUI is there a different permission required for Move-ADObject from a powershell script? I get this error for every computer object in my CSV but I confirmed that I can do a few of them manually in GUI.

Move-ADObject : Access is denied
At char:5
+ Move-ADObject -Identity $ComputerDN -TargetPath $targetou
+
+ CategoryInfo : PermissionDenied: [Move-ADObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.UnauthorizedAccessException, Microsoft.ActiveDirectory.Management.Commands.MoveADObject

is the script (minus my domain related information)
# Import the data from csv file and assign it to variable
$import_csv = Import-csv -path "C:\XXX\XXXcomputers.csv"

# Specify target OU where the users will be moved to
$targetou =

$import_csv | ForEach-object {

#retrieve DN of computer
$ComputerDN = (Get-adcomputer -Identity

write-host "Moving Accounts...."

# Move user to target OU. Remove the -WhatIF parameter after you tested.
Move-ADObject -Identity $ComputerDN -TargetPath $targetou
}
Write-Host "Completed move"

_dj_dubz_
Автор

How to move multiple users to multiple OU ?

girishdixit
Автор

I have a list.. i'd like to move them all

dasoultube