how to get a reverse without false positives or empty fields?

This topic contains 3 replies, has 4 voices, and was last updated by  Rob Simmers 3 months, 1 week ago.

  • Author
    Posts
  • #74944

    Sebastian Hernandez
    Participant

    I have a very small script that use to get a reverse info with a list of users in ADPS...


    $csv = Import-csv "C:\My Scripts\list.txt"
    $error.clear()
    foreach($User in $csv)
    {
    $User = $User.User
    $User
    Get-QADUser $User | ft name,DisplayName,Email,PrimarySMTPAddress >> reverse_file.csv
    }

    ... the problems come when, the list that some ask me to review doesn't have the exact info. This make that the result file return me a false positive or in case that the username been ambiguous, it return 2 or more similar results.

    How I can do to limit the query only to the value that is in the source file, and in case that the username doesn't exist write "something"?

  • #74948

    random commandline
    Participant
    $csv = Import-csv "C:\My Scripts\list.txt"
    $error.clear()
    foreach($User in $csv){
    $User = $User.User
    $User
    If ($qad = Get-QADUser $User) {$qad | Select-Object name,DisplayName,
    Email,PrimarySMTPAddress | export-csv .\reverse_file.csv} Else {"$user does not exist" | out-file .\no_user_file.txt -append}
    }
    
  • #74953

    Chris Bakker
    Participant

    If the rest is all the same:

    ...Select-Object -Unique...

  • #74987

    Rob Simmers
    Participant

    If the list has duplicates, you would do something like this:

    foreach($User in $csv | Select User -Unique){
    

You must be logged in to reply to this topic.