Error message "At least one rule must be specified" when uploading JSON file to create custom compliance policy in Intune

Houman Alavehzadeh 20 Reputation points
2025-03-13T15:37:17.52+00:00

Attempting to create a custom policy in Microsoft Intune to discover non-updated machines leads to an error message stating "At least one rule must be specified" when uploading a JSON file.

The PowerShell discovery script being used is as follows:

# Check for Windows Updates
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsInstalled=0")
# Check if there are any updates available
if ($SearchResult.Updates.Count -gt 0) {
    # Updates are available, mark the machine as noncompliant
    Write-Output "Machine is not compliant. Updates are available."
    # Add your code here to mark the machine as noncompliant in your system
} else {
    # No updates available, machine is compliant
    Write-Output "Machine is compliant. No updates available."
    # Add your code here to mark the machine as compliant in your system
} 

The JSON file being uploaded contains the following:

{
    "PolicyName": "WindowsUpdateCompliance",
    "Description": "Mark Windows machines as noncompliant if they are not updated",
    "ComplianceSettings": {
        "CheckForUpdates": true,
        "MarkAsNoncompliantIfNotUpdated": true,
        "Rules": [
            {
                "ruleName": "WindowsUpdateCheck",
                "ruleType": "Update",
                "ruleDescription": "Check if Windows updates are installed",
                "ComplianceCriteria": {
                    "UpdateStatus": "UpToDate"
                }
            }
        ]
    }
} 

A screenshot of the error when uploading the file is provided below:

User's image

Microsoft Intune Compliance
Microsoft Intune Compliance
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Compliance: Adhering to rules, standards, policies, and laws.
186 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Crystal-MSFT 52,816 Reputation points Microsoft External Staff
    2025-03-14T01:54:30.69+00:00

    @Houman Alavehzadeh, Thanks for posting in Q&A. The error message "At least one rule must be specified" suggests that Intune is not recognizing the rule you've defined in your JSON file.

    Discovery script detects the settings from the JSON file. The JSON file defines the custom settings and the values that you considered to be compliant.

    After reviewing the discovery script and JSON file, I find the format is not correct.

    https://learn.microsoft.com/en-us/mem/intune-service/protect/compliance-use-custom-settings

    For discovery script, it Identifies one or more settings, as defined in the JSON, and return a list of discovered values for those settings. You can change the script to add one variable to detect the windows update status and return the value with example like "return $hash | ConvertTo-Json -Compress"

    https://learn.microsoft.com/en-us/mem/intune-service/protect/compliance-custom-script#sample-discovery-script-for-windows

    For JSON File, we need to define the custom setting windows update status which you define in discovery script and the value we consider it to be compliant.

    https://learn.microsoft.com/en-us/mem/intune-service/protect/compliance-custom-json

    Here are some examples you can read as a reference:

    https://call4cloud.nl/custom-compliance-policy-intune/

    https://patchmypc.com/intune-compliance-policy

    Note: None-Microsoft link, just for the reference.

    Hope the above information can help.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.