2

Loaded two JSON files with Get-Content filename.JSON | ConvertFrom-Json

One object name $SubscriberEmail has the property name email

The second object name $ADEnabledUsersEmail has a property named Work Email

Trying to compare both objects and find the ones, not in the $ADEnabledUsersEmail object and Write-Out the name.

Here is the current foreach method but seems to output all the emails multiple times.

foreach($S in $SubscriberEmail ){
    foreach($A in $ADEnabledUsersEmail){
        if($A.'Work Email' -eq $S.email ){
            Write-Host "User is active"
        }else{
            Write-Host $s.email
        }
    }
}

1 Answer 1

2

If you want to filter an array you can use Where-Object or .Where() method or a loop with the right comparison operator. i.e.: -notin, -notcontains:

$SubscriberEmail.email.where({ $_ -notin $ADEnabledUsersEmail.'Work Email' })
$SubscriberEmail | Where-Object {
    $ADEnabledUsersEmail.'Work Email' -notcontains $_.email
}
foreach($email in $SubscriberEmail.email)
{
    if($email -notin $ADEnabledUsersEmail.'Work Email')
    {
        $email
    }
}

There are many more options to filter arrays, just search filtering arrays powershell on Google.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.