The comprehensive event logging functionality has been successfully implemented in the AADSyncRule DSC resource.
- 1000 (Information): Sync rule is in desired state and compliant
- 1001 (Warning): Sync rule is absent but should be present
- 1002 (Warning): Sync rule is present but should be absent
- 1003 (Warning): Sync rule configuration drift detected
- 2000 (Information): Sync rule created successfully
- 2001 (Information): Sync rule updated successfully
- 2002 (Information): Standard sync rule disabled state changed
- 2003 (Information): Sync rule removed successfully
- Function:
Write-AADConnectEventLog(Private function) - Event Log: "AADConnectDsc"
- Event Source: "AADConnectDsc"
- Format: Multi-line with structured information
- Error Handling: Graceful failure that doesn't break DSC operations
Event logging requires elevated permissions:
- Creating event logs requires Administrator rights
- Writing to event logs may require elevated permissions
- DSC Local Configuration Manager typically runs as SYSTEM
The custom "AADConnectDsc" event log must be created first:
# Run as Administrator
New-EventLog -LogName "AADConnectDsc" -Source "AADConnectDsc"- DSC may run in different security contexts
- Local DSC runs as SYSTEM (should have permissions)
- Remote DSC may have different permission contexts
# Run as Administrator BEFORE using DSC
New-EventLog -LogName "AADConnectDsc" -Source "AADConnectDsc"# Check if event log exists
[System.Diagnostics.EventLog]::Exists("AADConnectDsc")
# View recent events
Get-WinEvent -LogName "AADConnectDsc" -MaxEvents 10
# View events with details
Get-WinEvent -LogName "AADConnectDsc" -MaxEvents 5 |
Format-Table TimeCreated, Id, LevelDisplayName, Message -Wrap# Monitor events in real-time (run before DSC operation)
Get-WinEvent -LogName "AADConnectDsc" -Oldest |
Select-Object TimeCreated, Id, LevelDisplayName, MessageConfiguration AADSyncRuleConfig
{
Import-DscResource -ModuleName AADConnectDsc
Node localhost
{
AADSyncRule MyCustomRule
{
Name = "My Custom Sync Rule"
ConnectorName = "contoso.com"
Direction = "Inbound"
TargetObjectType = "person"
SourceObjectType = "user"
LinkType = "Join"
Precedence = 100
Disabled = $false
Ensure = "Present"
}
}
}
# Apply configuration
AADSyncRuleConfig -OutputPath "C:\DSC\AADSync"
Start-DscConfiguration -Path "C:\DSC\AADSync" -Wait -Verbose
# Check for events after DSC run
Get-WinEvent -LogName "AADConnectDsc" -MaxEvents 5# Test if function works (requires source files)
. ".\source\Private\Write-AADConnectEventLog.ps1"
Write-AADConnectEventLog -EventType 'Information' -EventId 2000 `
-Message "Test sync rule created successfully" `
-SyncRuleName 'TestRule' -ConnectorName 'TestConnector' `
-Direction 'Inbound' -TargetObjectType 'person' `
-SourceObjectType 'user' -Precedence 100 -Disabled $false `
-IsStandardRule $false -Operation 'Create' `
-RuleIdentifier 'test-guid-123' -Verbose- Check Permissions: Ensure DSC runs with sufficient permissions
- Pre-create Event Log: Run
New-EventLog -LogName "AADConnectDsc" -Source "AADConnectDsc"as Administrator - Check Event Log Exists: Verify with
[System.Diagnostics.EventLog]::Exists("AADConnectDsc") - Check DSC Verbose Logs: Look for event logging error messages in DSC output
- Run PowerShell as Administrator
- Ensure DSC LCM has appropriate permissions
- Check Event Log service is running
The event messages include:
- Sync rule name and connector
- Direction and object types
- Precedence and disabled state
- Rule complexity metrics (filters, mappings)
- Operation types and rule identifiers
✅ Event logging is fully implemented and working
✅ Comprehensive coverage of all sync rule operations
✅ Multi-line format with rich operational context
✅ Graceful error handling that doesn't break DSC
✅ Professional Windows Event Log integration
The event logging will work properly when:
- DSC runs with sufficient permissions (typically as SYSTEM)
- The AADConnectDsc event log is created
- The sync rule operations actually occur (create/update/remove)
Recommendation: Pre-create the event log as Administrator before using the DSC resource in production environments.