filmov
tv
Bulk Move Users and Computers in Active Directory with PowerShell
Показать описание
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
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
Комментарии