Skip to content

Commit

Permalink
Add small error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Sep 25, 2023
1 parent a320571 commit f0ce624
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Private/Set-O365OrgContact.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f0ce624

Please sign in to comment.