Created
March 6, 2019 07:33
-
-
Save jonimattila/e11d7dd51a65540f09535348a540a49e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CSV example name, username | |
# Import AD Module | |
import-module ActiveDirectory | |
# Import CSV | |
$MoveList = Import-Csv -Path "C:\temp\moveusers.csv" | |
# Specify target OU.This is where users will be moved. | |
$TargetOU = "OU=moveou,OU=users,DC=subdomain,DC=local" | |
# Import the data from CSV file and assign it to variable | |
$Imported_csv = Import-Csv -Path "C:\temp\moveusers.csv" | |
$Imported_csv | ForEach-Object { | |
# Retrieve DN of User. | |
$UserDN = (Get-ADUser -Identity $_.Name -Partition "DC=subdomain,DC=local" -Server "dc.subdomain.local" ).distinguishedName | |
Write-Host " Moving Accounts ..... " | |
# Move user to target OU. | |
Move-ADObject -Identity $UserDN -TargetPath $TargetOU -Partition "DC=subdomain,DC=local" -Server "dc.subdomain.local" | |
} | |
Write-Host " Completed move " | |
$total = ($MoveList).count | |
Write-Host " $total accounts have been moved succesfully..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment