csv - How can I use powershell to retrieve AD distinguishedName from the employeeID only? -


what i'm trying run script compares employee ids csv file ad, , if they're not in csv in ad should: - disabled - have termination date comment added description - move different ou

the script i'm using below disables account , adds comment, error when tries move different ou. error is: move-adobject : cannot find object identity: 'name1test' ...

i've tried lot of things adjust script samaccountname or distinguishedname using employeeid, i've had no luck. ideas?

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 user.     set-aduser -identity $name -enabled $false -description "terminated - $date"     # move user.     move-adobject -identity $name -targetpath $targetou } 

the distinguished name 1 of default properties automatically retrieved when ad user, need replace this:

$name = $term.samaccountname 

with this:

$name = $term.distinguishedname 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -