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

Get-WinEvent instead of Get-EventLog #443

Open
abyrd-mma opened this issue Feb 27, 2025 · 0 comments
Open

Get-WinEvent instead of Get-EventLog #443

abyrd-mma opened this issue Feb 27, 2025 · 0 comments

Comments

@abyrd-mma
Copy link

Problem description

Get-EventLog is deprecated in favor of Get-WinEvent and when trying to use WindowsEventLog from ComputerManagemntDsc with GuestConfig Agent I am getting an error message like the following

Verbose logs

The term 'Get-EventLog' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. The PowerShell DSC resource '[WindowsEventLog]LOG_NAME' with SourceInfo 'E:\agent\_work\1212\dev\build\configurations\dev\WindowsEventLog_LOG_NAME.ps1::6::9::WindowsEventLog' threw one or more non-terminating errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details. The SendConfigurationApply function did not succeed. LCM failed to start desired state configuration manually.

DSC configuration

Configuration WindowsEventLog_LOG_NAME
{
    Import-DSCResource -Name WindowsEventLog -ModuleName ComputerManagementDsc -ModuleVersion 10.0.0
    Node localhost
    {
        WindowsEventLog LOG_NAME
        {
            LogName           = 'LOG_NAME'
            RegisteredSource  = 'LOG_NAME'
            IsEnabled         = $true 
        }
    }
}

WindowsEventLog_LOG_NAME -OutputPath .\mof-files\WindowsEventLog_LOG_NAME\

Suggested solution

Remove Get-EventLog from the following functions Get-WindowsEventLogRestrictGuestAccess and Set-WindowsEventLogRetentionDays

Replace 717 and 971 with the following code

$matchingEventLog = Get-WinEvent -ListLog $Logname -ErrorAction Stop

Operating system the target node is running

OsName               : Microsoft Windows Server 2019 Standard

PowerShell version and build the target node is running

PowerShell ver 7 is what our build and deploy pipeline are running

ComputerManagementDsc version

Version 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant