Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, January 8, 2015 12:17 PM
I need move user for one OU another, but show error
this my script:
Import-Module activedirectory
$Users = Import-Csv -Delimiter ";" -Path "D:\Joan\teste.txt"
foreach ($User in $Users)
{
$DisplayName = $User.Usuarios
$TempUser = Get-ADUser -Filter { DisplayName -like $DisplayName }
Move-ADObject -Identity $DisplayName -TargetPath "OU=teste,DC=teste,DC=br"
}
This error:
ove-ADObject : Não é possível localizar um objeto com identidade: 'ALCIDES ALVES MACHADO ' em: 'DC=teste,DC=br'.
Em linha:8 caractere:14
- Move-ADObject <<<< -Identity $DisplayName -TargetPath "OU=teste,DC=teste,DC=br"
+ CategoryInfo : ObjectNotFound: (ALCIDES ALVES M... :ADObject) [Move-ADObject], ADIdentityNotFoundException
+ FullyQualifiedErrorId : Não é possível localizar um objeto com identidade: 'ALCIDES ALVES MACHADO ' em: 'DC=teste,DC=br'.,Microsoft.ActiveDirectory.M
anagement.Commands.MoveADObject
All replies (8)
Thursday, January 8, 2015 1:17 PM ✅Answered | 3 votes
You cannot use match in a filter.
Import-Module activedirectory
$Users=Import-Csv -Delimiter ";" -Path "D:\Joan\teste.txt"
foreach($User in $Users){
$DisplayName = $User.Usuarios
Get-ADUser -Filter { DisplayName -like $DisplayName } |
Move-ADObject -TargetPath "OU=teste,DC=teste,DC=br"
}
¯\(ツ)_/¯
Thursday, January 8, 2015 12:28 PM
Can you try this:
Import-Module activedirectory
$Users = Import-Csv -Delimiter ";" -Path "D:\Joan\teste.txt"
foreach ($User in $Users)
{
$DisplayName = $User.Usuarios
$TempUser = Get-ADUser -Filter { DisplayName -like $DisplayName }
Move-ADObject -Identity $TempUser.distinguishedname -TargetPath "OU=teste,DC=teste,DC=br"
}
Move-ADObject is expecting a distinguishedname or GUID to identify the object. As long as Get-ADUser returns a user object then this should work.
Thursday, January 8, 2015 12:48 PM
I try, but... :/
Move-ADObject : Não é possível validar o argumento no parâmetro 'Identity'. O argumento é nulo. Forneça um argumento que não seja nulo e tente o comando novamente.
Em linha:8 caractere:25
+ Move-ADObject -Identity <<<< $TempUser.distinguishedname -TargetPath "OU=teste,DC=teste,DC=br"
+ CategoryInfo : InvalidData: (:) [Move-ADObject], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.MoveADObject
Thursday, January 8, 2015 1:04 PM
According to this error, the $Tempuser variable is null. This means that Get-ADUser is not returning anything. Try running get-aduser separately using the values from the csv file to see if it returns a user.
Thursday, January 8, 2015 1:10 PM
Agreed with the above, another thing you can do is actually debug it in ISE. If you open ISE save the script, click on the foreach part and press F9. You will enter a breakpoint and then run the script with F5, this will allow you to hover over $user in $users to see if its pulling anything back. Press F11 to jump to the next part and you will see where its not working.
Also instead of -like id use -match
If this is helpful please mark it so. Also if this solved your problem mark as answer.
Thursday, January 8, 2015 1:18 PM | 1 vote
Warning: Display name is not unique. If the CSV has duplicate displaynames the codewil always fail no matter how you do it.
¯\(ツ)_/¯
Monday, January 12, 2015 11:57 AM
Tanks!! ;)
Wednesday, July 11, 2018 2:30 PM | 1 vote
Try this script:
#################################################################
# Import AD Module
import-module ActiveDirectory
# Import CSV
$MoveList = Import-Csv -Path "C:\Temp\Acc_MoveList.csv"
# Specify target OU.This is where users will be moved.
$TargetOU = "OU=SVC_Users,OU=VA,DC=TekPros,DC=com"
# Import the data from CSV file and assign it to variable
$Imported_csv = Import-Csv -Path "C:\temp\Acc_MoveList.csv"
$Imported_csv | ForEach-Object {
# Retrieve DN of User.
$UserDN = (Get-ADUser -Identity $_.Name).distinguishedName
Write-Host " Moving Accounts ..... "
# Move user to target OU.
Move-ADObject -Identity $UserDN -TargetPath $TargetOU
}
Write-Host " Completed move "
$total = ($MoveList).count
Write-Host " $total accounts have been moved succesfully..."
Notes:Modify CSV File pathModify TargetPath of wanted OUMake the CSV file one column and first row of the CSV file "Name" and below rows are "usernames".