Skip to content

Commit 37ae62d

Browse files
Merge pull request #6790 from FabienTschanz/fix/implicit-remoting
Prevent implicit remoting because of Windows Events
2 parents df9b055 + 54d036a commit 37ae62d

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
* Fixed an issue where `Rename-M365DSCCimInstanceParameter` omitted values.
6565
FIXES [#6727](https://github.com/microsoft/Microsoft365DSC/issues/6727)
6666
FIXES [#6779](https://github.com/microsoft/Microsoft365DSC/issues/6779)
67+
* M365DSCLogEngine
68+
* Replaced deprecated Windows Event PowerShell cmdlets with .NET.
6769
* M365DSCReverse
6870
* Added logic to clean up temporary files after export.
6971
* Added `TenantGuid` entry to the `ConfigurationData.psd1` file during export.

Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,13 @@ function Add-M365DSCEvent
203203
}
204204
else
205205
{
206-
if ([System.Diagnostics.EventLog]::Exists($LogName) -eq $false)
206+
try
207207
{
208-
# Create event log
209-
$null = New-EventLog -LogName $LogName -Source $Source
208+
[System.Diagnostics.EventLog]::CreateEventSource($Source, $LogName)
210209
}
211-
else
210+
catch [System.Security.SecurityException]
212211
{
213-
try
214-
{
215-
[System.Diagnostics.EventLog]::CreateEventSource($Source, $LogName)
216-
}
217-
catch [System.Security.SecurityException]
218-
{
219-
Write-Verbose -Message "[WARNING] Not all event logs could be searched. Source might exist in another event log."
220-
}
212+
Write-Verbose -Message "[WARNING] Not all event logs could be searched. Source might exist in another event log."
221213
}
222214
}
223215

@@ -246,8 +238,7 @@ function Add-M365DSCEvent
246238

247239
try
248240
{
249-
Write-EventLog -LogName $LogName -Source $Source `
250-
-EventId $EventID -Message $outputMessage -EntryType $EntryType -ErrorAction Stop
241+
[System.Diagnostics.EventLog]::WriteEntry($Source, $outputMessage, $EntryType, $EventID)
251242
}
252243
catch
253244
{
@@ -378,7 +369,7 @@ function Export-M365DSCDiagnosticData
378369
try
379370
{
380371
Write-Host ' * Anonymizing DSC Event Log' -ForegroundColor Gray
381-
Get-EventLog -LogName 'M365Dsc' -After $afterDate | Export-Csv $evtExportLog -NoTypeInformation
372+
Get-WinEvent -FilterHashtable @{ LogName = 'M365Dsc'; StartTime = $afterDate } -ErrorAction SilentlyContinue | Export-Csv $evtExportLog -NoTypeInformation
382373
if ($Anonymize)
383374
{
384375
$newLog = Import-Csv $evtExportLog

0 commit comments

Comments
 (0)