Link to home
Start Free TrialLog in
Avatar of Mohammed Hamada
Mohammed HamadaFlag for Portugal

asked on

Distinguishing Positive from Negative result in Powershell

I would like to know if it's possible to use IF in powershell to distinguish the positive/negative results after using a bulk command.

The command-let I am using is as following

#Set matching contacts with Legacy Exchange DN from Source Forest
foreach ($contact in $LocalContacts){
    $Identity = $contact.alias

if ((Set-Mailcontact $SourceSMTP -EmailAddresses @{Add="X500:$LegacyDN"} )) {
write-host User $Contact.Name has Legacy Exchange DN added to their proxy address -ForegroundColor Green -BackgroundColor Black }else{

Write-Host User $Contact.Name Legacy has not been added successfully  -ForegroundColor Red -BackgroundColor Black
 
}
} 
}

Open in new window


In this code both negative and positive results are appearing in Red with the result  "User Legacy has not been added successfully"
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mohammed Hamada

ASKER

Thank you. that did it .