Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M365DSCLogEngine causes errors in Azure Automation Run Books #2236

Closed
andikrueger opened this issue Aug 29, 2022 · 1 comment · Fixed by #2405 or #2421
Closed

M365DSCLogEngine causes errors in Azure Automation Run Books #2236

andikrueger opened this issue Aug 29, 2022 · 1 comment · Fixed by #2405 or #2421
Labels
Bug Something isn't working Core Engine

Comments

@andikrueger
Copy link
Collaborator

When running M365DSC Exports within Azure Automation Run Books there are some errors reported, that are cause by M365DSCLogEngine.

The code within the run book is run as administrator.

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
true

Looks like there is an issue with writing to the event log.

Write-EventLog : The registry key for the log "M365DSC" for source "MSFT_SPOAccessControlSettings" could not be opened.
At C:\Modules\User\Microsoft365DSC\modules\M365DSCLogEngine.psm1:142 char:9
+         Write-EventLog -LogName $LogName -Source $Source `
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (:) [Write-EventLog], Exception
    + FullyQualifiedErrorId : AccessDenied,Microsoft.PowerShell.Commands.WriteEventLogCommand

A possible solution could be to add a check, if run in Azure Automation like the fixes for #2233

@andikrueger andikrueger added Bug Something isn't working Core Engine labels Aug 29, 2022
@NikCharlebois
Copy link
Collaborator

Will simply be wrapping it in its own try/catch block instead. There are other scenarios that would require this such as when running from containers.

NikCharlebois added a commit to NikCharlebois/Microsoft365DSC that referenced this issue Oct 17, 2022
NikCharlebois added a commit that referenced this issue Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Core Engine
Projects
None yet
2 participants