none
Compare field from CSV to AD RRS feed

  • Question

  • I need to create a list containing the samaccount name of users in two different AD systems. I have a CSV file with the information from one of the AD systems and need to match it to the other system using employeenumber.

    The CSV has the following columns

    surname, givenname,samaccountname,empolyeenumber,enabled

    I have started testing with this code

    $Users=import-csvi:\employeenumber\adusers.csv


    foreach

    ($Userin$Users) {

       

    $user.samaccountname

       

    $user.employeenumber

       

    get-aduser-filter*-propertiesemployeenumber|where-object{$_.employeenumber -eq$user.employeenumber}

    }

    The display of samaccount and employeenumber are for debug purposes and are displaying correctly.  The problem is that the comparison pulls all of the users in ASD that have a Null value in employee number.

    The employee numbers should match in each system.  Ultimately I want to output another CSV with both samaccount names.

    I do not see why the where object is does not match.

    Any help would be appreciated.

    Wednesday, February 8, 2017 8:51 PM

Answers

  • Please do not post colorized code. It is impossible to read or copy.  Please use the code posting tool on the edit bar.

    Try this.

    Compare-Object $csv1 $csv2 -Properties EmployeeNumber -IncludeEqual

    help compare-object -full

    Or

    Get-Aduser -Filter "EmployeeNumber -eq '$($user.EmployeeNumber)'"


    \_(ツ)_/


    • Edited by jrv Wednesday, February 8, 2017 11:25 PM
    • Marked as answer by JRussell97 Thursday, February 9, 2017 3:13 PM
    Wednesday, February 8, 2017 11:25 PM

All replies

  • Please do not post colorized code. It is impossible to read or copy.  Please use the code posting tool on the edit bar.

    Try this.

    Compare-Object $csv1 $csv2 -Properties EmployeeNumber -IncludeEqual

    help compare-object -full

    Or

    Get-Aduser -Filter "EmployeeNumber -eq '$($user.EmployeeNumber)'"


    \_(ツ)_/


    • Edited by jrv Wednesday, February 8, 2017 11:25 PM
    • Marked as answer by JRussell97 Thursday, February 9, 2017 3:13 PM
    Wednesday, February 8, 2017 11:25 PM
  • Thanks for the help.  I got it to work last night but I will try your suggestion for the filter as it may be faster than what I am doing now.

    I will use the code tool next time.  I did not see it when I posted.

    Thursday, February 9, 2017 3:15 PM