diff --git a/Private/Set-O365OrgContact.ps1 b/Private/Set-O365OrgContact.ps1 index 089d980..5553c15 100644 --- a/Private/Set-O365OrgContact.ps1 +++ b/Private/Set-O365OrgContact.ps1 @@ -43,23 +43,28 @@ } if ($MismatchedPropertiesMailContact.Count -gt 0 -or $MismatchedPropertiesContact.Count -gt 0) { Write-Color -Text "[i] ", "Mismatched properties for ", $Source.DisplayName, " / ", $Source.PrimarySmtpAddress, " are: ", ($MismatchedPropertiesMailContact + $MismatchedPropertiesContact -join ', ') -Color Yellow, White, DarkCyan, White, Cyan - + $ErrorValue = $false if ($MismatchedPropertiesMailContact.Count -gt 0) { - Write-Color -Text "[*] ", "Updating mail contact for ", $Source.DisplayName, " / ", $Source.PrimarySmtpAddress -Color Yellow, White, DarkCyan, White, Cyan + Write-Color -Text "[*] ", "Updating mail contact for ", $Source.DisplayName, " / ", $Source.PrimarySmtpAddress -Color Yellow, Green, DarkCyan, White, Cyan try { Set-MailContact -Identity $MailContact.Identity -WhatIf:$WhatIfPreference -ErrorAction Stop @MismatchedMailContact } catch { - Write-Color -Text "[e] ", "Failed to update mail contact. Error: ", ($_.Exception.Message -replace ([Environment]::NewLine), " " )-Color Yellow, White, Red + $ErrorValue = $true + Write-Color -Text "[e] ", "Failed to update mail contact. Error: ", ($_.Exception.Message -replace ([Environment]::NewLine), " " )-Color Red, White, Red } } if ($MismatchedPropertiesContact.Count -gt 0) { - Write-Color -Text "[*] ", "Updating contact for ", $Source.DisplayName, " / ", $Source.PrimarySmtpAddress -Color Yellow, White, DarkCyan, White, Cyan + Write-Color -Text "[*] ", "Updating contact for ", $Source.DisplayName, " / ", $Source.PrimarySmtpAddress -Color Yellow, Green, DarkCyan, White, Cyan try { Set-Contact -Identity $MailContact.Identity -WhatIf:$WhatIfPreference -ErrorAction Stop @MismatchedContact } catch { - Write-Color -Text "[e] ", "Failed to update contact. Error: ", ($_.Exception.Message -replace ([Environment]::NewLine), " " )-Color Yellow, White, Red + $ErrorValue = $true + Write-Color -Text "[e] ", "Failed to update contact. Error: ", ($_.Exception.Message -replace ([Environment]::NewLine), " " )-Color Red, White, Red } } + if ($ErrorValue -eq $false) { + $true + } } else { #Write-Color -Text "[i] ", "No mismatched properties for ", $Source.DisplayName, " / ", $Source.PrimarySmtpAddress -Color Yellow, White, DarkCyan, White, Cyan }