Skip to content

Instantly share code, notes, and snippets.

@alexverboon
Created August 15, 2024 11:49
Show Gist options
  • Save alexverboon/b0e302d4fa26d8f41e5ccda45bd7d959 to your computer and use it in GitHub Desktop.
Save alexverboon/b0e302d4fa26d8f41e5ccda45bd7d959 to your computer and use it in GitHub Desktop.
Microsoft Intune - Windows 11 - ConfigRefresh

Config Refresh - PowerShell stuff

Get Config Refresh Events from the Event Log

# Define the event log name
$logName = "Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Operational"

# Define the event IDs you want to retrieve
$eventIDs = @(4200, 4201, 4202) + (4203..4214)

# Retrieve the events from the specified log and event IDs
$events = Get-WinEvent -FilterHashtable @{LogName=$logName; Id=$eventIDs}

# Display the retrieved events
$events | Format-List

To determine when the next Config Refresh will take place based on the last successful time (Event ID 4202) plus 30 minutes, you can use the following PowerShell script:

# Define the event log name
$logName = "Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Operational"

# Define the event ID for a successful config refresh
$successEventID = 4202

# Retrieve the most recent successful config refresh event
$lastSuccessEvent = Get-WinEvent -FilterHashtable @{LogName=$logName; Id=$successEventID} -MaxEvents 1

# Check if a successful event was found
if ($lastSuccessEvent) {
    # Get the time of the last successful config refresh
    $lastSuccessTime = $lastSuccessEvent.TimeCreated

    # Calculate the next config refresh time (30 minutes after the last success)
    $nextConfigRefreshTime = $lastSuccessTime.AddMinutes(30)

    # Display the next config refresh time
    Write-Output "The next Config Refresh is expected to take place at: $nextConfigRefreshTime"
} else {
    Write-Output "No successful Config Refresh event (Event ID 4202) found."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment