How can I use powershell to retrieve AD distinguishedName from the employeeID only? <p>What I'm trying to do is run a script which compares employee IDs from a CSV file to AD, and if they're NOT in the CSV but ARE in AD they should: - be disabled - have a termination date comment added to the description - move to a different OU</p> <p>The script I'm using below disables the account and adds the comment, but I get an error when it tries to move to different OU. The error is: Move-ADObject : Cannot find an object with identity: 'name1test' ...</p> <p>I've tried a lot of things to adjust the script to get the samAccountName or distinguishedName using only the employeeID, but I've had no luck. Any ideas?</p> <pre><code>Import-Module ActiveDirectory $TargetOU = "ou=Term,ou=Logins,dc=domain,dc=com" $Date = Get-Date -Format MM-dd-yyyy $Users = Import-Csv c:\ADTerm.csv | Select-object -ExpandProperty EmployeeID $Terms = Get-ADUser -filter * -SearchBase "ou=Test,ou=Logins,dc=domain,dc=com" -Properties EmployeeID | Where-Object{$_.EmployeeID -and ($Users -notcontains $_.EmployeeID)} ForEach ($Term in $Terms) { # Retrieve user sAMAccountName. $Name = $Term.sAMAccountName # Disable the user. Set-ADUser -Identity $Name -Enabled $False -Description "Terminated - $Date" # Move the user. Move-ADObject -Identity $Name -TargetPath $TargetOU } </code></pre>