Skip to content

Update-IntuneDeviceConfigurationPolicy - Does not throw an exception if an error occurs #5055

@FabienTschanz

Description

Description of the issue

Currently, the cmdlet Update-IntuneDeviceConfigurationPolicy does not throw if an error occurs during execution. Instead, it simply logs the error to the event channel and returns null to the caller.

It currently looks like the following:

try
    {
        Invoke-MgGraphRequest -Method PUT -Uri $Uri -Body $body -ErrorAction Stop
    }
    catch
    {
        New-M365DSCLogEntry -Message 'Error updating data:' `
            -Exception $_ `
            -Source $($MyInvocation.MyCommand.Source) `
            -TenantId $TenantId `
            -Credential $Credential

        return $null
    }

As a consumer of the cmdlet, I would like to know if an error happened and for me, it would be the best if the execution is stopped and the exception is thrown to the higher levels to have them handle the issue. So the updated catch clause should look like the following in my opinion:

catch
    {
        New-M365DSCLogEntry -Message 'Error updating data:' `
            -Exception $_ `
            -Source $($MyInvocation.MyCommand.Source) `
            -TenantId $TenantId `
            -Credential $Credential

        throw
    }

Instead of returning null, I believe it's better if we rethrow the exception to stop the execution flow and let the caller of the cmdlet handle the exception. What do you think?

For visibility: @ricmestre

Microsoft 365 DSC Version

DEV

Which workloads are affected

Intune

The DSC configuration

No response

Verbose logs showing the problem

No response

Environment Information + PowerShell Version

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions