none
PowerShell looks up domain accounts with the same properties RRS feed

  • Question

  • Hello
    I want to find accounts that were created at the same time as the last password change
    When I run the script, the result is "different.". Some of the actual accounts are the same, but they also return different results

    Please help analyze

    $users Get-ADUser -SearchBase "OU=****" -Filter * -Properties whenCreated,PasswordLastSet
    foreach($user in $users){
        If($user.whenCreated -eq $user.PasswordLastSet){
            Write host "same"
        }else{
            Write host "different"
        }
    }


    • Edited by D Wang Wednesday, January 15, 2020 6:51 AM
    Wednesday, January 15, 2020 1:12 AM

All replies

  • Why is it so hard for people wanting to be techs to understand how to do something as simple as posting code that is formatted correctly. Please edit and make your code syntactically correct and readable:

    The PowerShell Best Practices and Style Guide


    \_(ツ)_/

    Wednesday, January 15, 2020 2:34 AM
  • If you drop all of the nonsense in the code and format it so that it is readable the problems will be obvious:

    The following is the only thing that is useful in your code.

    $users Get-ADUser -SearchBase "OU=****" -Filter * -Properties whenCreated,PasswordLastSet
    foreach($user in $users){
        If($user.whenCreated -eq $user.PasswordLastSet){
            Write host "same"
        }else{
            Write host "different"
        }
    }

    In any case what you are trying to do makes no sense and will never produce a result.

    You need to be clear about what you want to do.

    Read the following for guidelines: How to ask questions in a technical forum


    \_(ツ)_/


    • Edited by jrv Wednesday, January 15, 2020 2:40 AM
    Wednesday, January 15, 2020 2:40 AM
  • I know it's wrong
    Wednesday, January 15, 2020 6:59 AM