locked
Compare users that are in both variables RRS feed

  • Question

  • Hi, i have an AD query that gets me a list of users $adusers.samaccountname

    I have a second list of users in a second variable $customer.username

    $adusers                                                $customer

    samaccountname                                    username

    ---------------------                                   ------------------------

    user1                                                     user2

    user2                                                     user3

    user3

    user4

    I want to compare both variables and get the users from $adusers that are also in $customer

    I have done like this:

    foreach ($user in $adusers) {
       if ( $user.samaccountname -contains $customer.username) {
         $result=  $user.samaccountname 
    
       
    }
    }

    It only returns 1 value, and that user is from $adusers and also is in $customer.

    But i know there are more users, but they are not showing.

    any ideas?

    thansk

    Tuesday, April 2, 2013 11:08 AM

Answers

  • foreach ($user in $adusers) {
       if ($customer -contains $user.samaccountname ) {
         $user.samaccountname 
    }
    }
    try this way, You should learn Powershell basics first so you can notice the reason for nothing on the screen
    • Marked as answer by slowscripter Tuesday, April 2, 2013 12:51 PM
    Tuesday, April 2, 2013 12:29 PM

All replies

  • you check if a user contains different user

    You should check if an array contains user

    foreach ($user in $adusers) {
       if ($customer -contains $user.samaccountname ) {
         $result=  $user.samaccountname 
    }
    }

    Tuesday, April 2, 2013 11:14 AM
  • Hi Blinrood,

    Unfortunately your query doesn't return anything.

    Is that the full code?

    Thanks

    Tuesday, April 2, 2013 11:26 AM
  • foreach ($user in $adusers) {
       if ($customer -contains $user.samaccountname ) {
         $user.samaccountname 
    }
    }
    try this way, You should learn Powershell basics first so you can notice the reason for nothing on the screen
    • Marked as answer by slowscripter Tuesday, April 2, 2013 12:51 PM
    Tuesday, April 2, 2013 12:29 PM
  • Hi, thanks for your help.

    It shows them now.

    You are right.. i need to start looking into powershell more intensively.

    Regards

    Tuesday, April 2, 2013 12:52 PM