Close Menu
Peter Klapwijk – In The Cloud 24-7Peter Klapwijk – In The Cloud 24-7
    Facebook X (Twitter) Instagram
    Peter Klapwijk – In The Cloud 24-7Peter Klapwijk – In The Cloud 24-7
    • Home
    • Intune
    • Windows
      • Modern Workplace
    • macOS
    • Android
    • iOS
    • Automation
      • Logic Apps
      • Intune Monitoring
      • GitHub
    • Security
      • Passwordless
      • Security
    • Speaking
    • About me
    Peter Klapwijk – In The Cloud 24-7Peter Klapwijk – In The Cloud 24-7
    Home»Intune»Update Windows Defender during Windows Autopilot enrollments
    Intune

    Update Windows Defender during Windows Autopilot enrollments

    Peter KlapwijkBy Peter KlapwijkMay 16, 2025Updated:May 16, 202523 Mins Read

    Today a short post about a way to forcefully update Windows Defender Antimalware during our Windows Autopilot enrollments.

    When a Windows device is enrolled by an end-user the Windows Defender Antimalware version might be outdated. And because of that, sometimes even real-time protection is turned off. When Windows Update is running, the Antimalware version will get an update sooner or later and real-time protection turned on. But when your company uses a Intune compliance policy in which a Microsoft Defender Antimalware minimum version is required and no grace period is used, that might give your end-user a bad user experience. The device will be marked as non compliant until the Antimalware version is updated.

    With this PowerShell script we can forcefully trigger for an Antimalware update. If we package the script into a WIN32 app, we can make sure the script is run during Autopilot enrollments, and Defender is updated to the latest version before the user signs into the device.

    The script can be found on my GitHub repo.

    The script

    To update Defender their is not much more needed as a PowerShell one-liner. I added that to a script with some logging and wrapped that as WIN32 application. This way I can deploy it as application during Autopilot enrollment and if needed set it as dependency to another app. But you can also change the script to your own needs and deploy it as ‘normal’ script with Intune.

    Let’s see what’s in the script.

    As the Microsoft Intune Management Extension might start a 32-bit PowerShell instance, the script first restarts as 64-bit PS instance.

    In the functions region, we define a CleanUpAndExit function, which is also used for Intune detection when wrapped as a win32 package.

    And a transcript is started that writes a log file to %programdata%\Microsoft\IntuneManagementExtension\Logs so the log file can be remotely collected when using the Intune diagnostics feature.

    The script first collects the current Windows Defender Status and writes that to the log file:

    Get-MpComputerStatus | FL AMEngineVersion,AMProductVersion,AntivirusSignatureLastUpdated,RealTimeProtectionEnabled

    Next, it triggers a Defender update directly from the Microsoft Malware Protection Center (and bypassing Windows Update):

    $MpCmdRun = "C:\Program Files\Windows Defender\MpCmdRun.exe"
    If (Test-Path $MpCmdRun -PathType Leaf) {
    
        Write-Output "Force Windows Defender Update"
        $UpdateResult = & $MpCmdRun -SignatureUpdate -MMPC
        Write-Output $UpdateResult 
    
    } Else {
    
        Write-Output "Cannot find the Microsoft Antimalware Service Command Line Utility: $MpCmdRun"
    }

    And after triggering the update, the updates Defender status is retrieved to write to the log file.

    After that it runs the cleanup and exit function and writes the status to the registry, which can be used for detection in Intune. And that’s already it.

    Intune install and detection

    In case you also want to deploy the script as WIN32 applications I’ll show the install command and detection for this script.

    The install command is like this (depending on the PS1 file name):
    PowerShell.exe -ExecutionPolicy Bypass -file .\WindowsDefenderUpdateV1.0.ps1

    And the detection rule that checks the registry:
    HKEY_LOCAL_MACHINE\Software\Klapwijk\WindowsDefenderUpdate\v1.0

    End-result

    There is not much to write about the end-result.
    As we can see in the log file, Defender was outdated and after running the script it runs the latest version.

    Thanks for reading and have a nice day!

    Intune Microsoft Defender Privilege Endpoint Management Security Windows Windows 11
    Share. Facebook Twitter LinkedIn Email WhatsApp
    Peter Klapwijk
    • Website
    • X (Twitter)
    • LinkedIn

    Peter is a Security (Intune) MVP since 2020 and is working as Modern Workplace Engineer at Wortell in The Netherlands. He has more than 15 years of experience in IT, with a strong focus on Microsoft technologies like Microsoft Intune, Windows, and (low-code) automation.

    Related Posts

    Manage Microsoft 365 Apps updates with Cloud Update

    June 26, 2024

    Configure Windows Update for Business reporting

    June 8, 2023

    Enable passwordless security key sign-in in Hybrid Azure Active Directory environments

    February 25, 2020
    View 2 Comments

    2 Comments

    1. Carl on May 19, 2025 10:31

      Hi Peter – great idea and script…I’m considering running it as a platform script though. I know we lose visibility of the code this way but it feels nice to get this update executed as soon as possible – did you consider this approach and already rule it out? thanks 👍

      Reply
      • Peter Klapwijk on May 22, 2025 20:19

        Hi Carl,

        I didn’t try is as a platform script, but don’t see a reason it shouldn’t work as platform script.

        Regards,

        Peter

        Reply
    Leave A Reply Cancel Reply

    Peter Klapwijk

    Hi! Welcome to my blog post.
    I hope you enjoy reading my articles.

    Hit the About Me button to get in contact with me or leave a comment.

    Awards
    Sponsor
    Latest Posts

    Hide the “Turn on an ad privacy feature” pop-up in Chrome with Microsoft Intune

    April 19, 2025

    How to set Google as default search provider with Microsoft Intune

    April 18, 2025

    Using Windows Autopilot device preparation with Windows 365 Frontline shared cloud PCs

    April 13, 2025

    Using Visual Studio with Microsoft Endpoint Privilege Management, some notes

    April 8, 2025
    follow me
    • Twitter 4.8K
    • LinkedIn 6.1K
    • YouTube
    • Bluesky 1.5K
    Tags
    Administrative Templates Android Automation Autopilot Azure Azure AD Browser Conditional Access Edge EMS Exchange Online Feitian FIDO2 Flow Google Chrome Graph Graph API Identity Management Intune Intune Monitoring iOS KIOSK Logic Apps macOS MEM MEMMonitoring Microsoft 365 Microsoft Edge Microsoft Endpoint Manager Modern Workplace Office 365 OneDrive for Business Outlook Passwordless PowerApps Power Automate Security SharePoint Online Teams Windows Windows 10 Windows10 Windows 11 Windows Autopilot Windows Update
    Copy right

    This information is provided “AS IS” with no warranties, confers no rights and is not supported by the authors, or In The Cloud 24-7.

     

    Copyright © 2025 by In The Cloud 24-7/ Peter Klapwijk. All rights reserved, No part of the information on this web site may be reproduced or posted in any form or by any means without the prior written permission of the publisher.

    Shorthand; Don’t pass off my work as yours, it’s not nice.

    Recent Comments
    • Adam on Get notified on expiring Azure App Registration client secrets
    • Peter Klapwijk on Update Windows Defender during Windows Autopilot enrollments
    • Rob van de Ven on Add a certificate to the Trusted Publishers with Intune without reporting errors
    • Carl on Update Windows Defender during Windows Autopilot enrollments
    • Peter Klapwijk on The next step in a passwordless Windows experience
    most popular

    Application installation issues; Download pending

    October 1, 2024

    Restrict which users can logon into a Windows 10 device with Microsoft Intune

    April 11, 2020

    How to change the Windows 11 language with Intune

    November 11, 2022

    Update Microsoft Edge during Windows Autopilot enrollments

    July 9, 2024
    Peter Klapwijk – In The Cloud 24-7
    X (Twitter) LinkedIn YouTube RSS Bluesky
    © 2025 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.

    Manage Cookie Consent
    To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
    Functional Always active
    The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
    Preferences
    The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
    Statistics
    The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
    Marketing
    The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
    Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
    View preferences
    {title} {title} {title}