Skip to content

Commit eb5da4e

Browse files
committed
fix error handling
1 parent 37a2326 commit eb5da4e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardSPEmailAttestation.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,26 @@ function Invoke-CIPPStandardSPEmailAttestation {
3535

3636
$CurrentState = Get-CIPPSPOTenant -TenantFilter $Tenant | Select-Object -Property EmailAttestationReAuthDays, EmailAttestationRequired
3737

38-
$StateIsCorrect = ($CurrentState.EmailAttestationReAuthDays -eq $Settings.Days) -and
38+
$StateIsCorrect = ($CurrentState.EmailAttestationReAuthDays -eq [int]$Settings.Days) -and
3939
($CurrentState.EmailAttestationRequired -eq $true)
4040

4141
if ($Settings.remediate -eq $true) {
4242
if ($StateIsCorrect -eq $true) {
4343
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'SharePoint reauthentication with verification code is already restricted.' -Sev Info
4444
} else {
4545
$Properties = @{
46-
EmailAttestationReAuthDays = $Settings.Days
46+
EmailAttestationReAuthDays = [int]$Settings.Days
4747
EmailAttestationRequired = $true
4848
}
4949

5050
try {
51-
Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
52-
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Successfully set reauthentication with verification code restriction.' -Sev Info
51+
$Response = Get-CIPPSPOTenant -TenantFilter $Tenant | Set-CIPPSPOTenant -Properties $Properties
52+
if ($Response.ErrorInfo.ErrorMessage) {
53+
$ErrorMessage = Get-NormalizedError -Message $Response.ErrorInfo.ErrorMessage
54+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Failed to set reauthentication with verification code restriction. Error: $ErrorMessage" -Sev Error
55+
} else {
56+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'Successfully set reauthentication with verification code restriction.' -Sev Info
57+
}
5358
} catch {
5459
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
5560
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Failed to set reauthentication with verification code restriction. Error: $ErrorMessage" -Sev Error

0 commit comments

Comments
 (0)