Keeping systems secure and up-to-date is a critical task for IT administrators, especially in large environments. Zero touch patch management allows organizations to automate the deployment of updates without manual intervention, reducing downtime and improving security posture. By leveraging PowerShell scripts combined with Microsoft Intune, you can create a streamlined, hands-free patch management process that ensures devices stay current with minimal effort. This guide walks you through setting up a reliable, automated patch management system using PowerShell and Intune, providing a practical approach to maintaining your fleet of devices efficiently.
What You’ll Need
- Microsoft Intune subscription with appropriate administrative privileges
- Azure Active Directory (Azure AD) account with Intune access
- PowerShell 7+ installed on your management workstation
- Basic knowledge of PowerShell scripting
- Devices enrolled in Intune and compliant with management policies
- Access to the Microsoft Endpoint Manager admin center
Step-by-Step
- Plan Your Patch Strategy: Identify which updates you want to deploy (e.g., Windows updates, third-party patches). Decide on deployment schedules and compliance policies within Intune.
- Create PowerShell Script for Patch Management: Develop a script that checks for available updates, downloads, and installs them. For example:
- Test Your Script Locally: Run your PowerShell script on a test device to ensure it functions correctly and handles updates as expected.
- Prepare the Script for Deployment: Save your script as a .ps1 file and ensure it has proper error handling and logging for troubleshooting.
- Create a PowerShell Script Policy in Intune:
- Navigate to the Microsoft Endpoint Manager admin center.
- Select Devices > PowerShell > Scripts.
- Click Add and upload your script.
- Configure settings such as run frequency, user context, and execution rights.
- Assign the Script to Devices: Select the device groups or users you want to target with your patch management script. Confirm assignments and save the policy.
- Monitor Deployment and Compliance: Use Intune reports and logs to verify script execution, update installation status, and troubleshoot issues.
- Automate and Schedule Regular Runs: Configure your script to run at regular intervals (e.g., weekly) by leveraging Intune’s scheduled deployment options or Windows Task Scheduler if needed for more advanced control.
Install-WindowsUpdate -AcceptAll -AutoReboot
(Note: You may need to install the Windows Update module or use third-party modules like PSWindowsUpdate.)
Common Mistakes
- Not testing scripts thoroughly before deployment, leading to failed updates or system issues.
- Ignoring device compliance policies, which can cause updates not to install on non-compliant devices.
- Using overly complex scripts without proper error handling, making troubleshooting difficult.
- Failing to monitor deployment logs, resulting in missed updates or unresolved errors.
- Disregarding network or firewall restrictions that might block update traffic.
Tips
- Start with simple scripts and gradually add complexity as needed.
- Leverage PowerShell modules like PSWindowsUpdate for more control over Windows updates.
- Use Intune’s reporting features to track deployment success and troubleshoot failures.
- Ensure devices are enrolled and compliant before deploying scripts for reliable results.
- Document your scripts and deployment plans for future reference and audits.
Troubleshooting
If your patch management deployment does not go as planned, follow these steps:
- Check Deployment Reports: Review Intune’s device and script deployment reports to identify failed devices or errors.
- Verify Script Execution: Log into target devices and manually run the script to see if it executes correctly. Check for errors or permission issues.
- Review Logs: Enable detailed logging within your script to capture errors. Use Event Viewer or custom log files for analysis.
- Network and Firewall Checks: Ensure devices can reach Windows Update servers or third-party sources without restrictions.
- Adjust Script Permissions: Confirm the script runs with appropriate privileges—often as SYSTEM or administrator.
- Update the Script: Modify your script based on errors, adding retry logic or error handling as needed.
- Reschedule or Redeploy: After fixing issues, reschedule the script deployment and monitor for success.
Frequently Asked Questions
1. Can I automate patch management for third-party applications with PowerShell and Intune?
Yes, but it requires custom scripts or third-party modules designed for specific applications. PowerShell can automate third-party patching if scripts are tailored accordingly.
2. How often should I schedule patch deployment scripts?
Typically, weekly or bi-weekly schedules work well, balancing security needs and network impact. Adjust based on your organization’s policies.
3. What permissions are needed to run PowerShell scripts via Intune?
Scripts should run with SYSTEM or administrator privileges to install updates effectively.
4. How do I ensure compliance after deploying patches?
Use Intune’s compliance policies and reporting features to verify devices are up-to-date and meet your security standards.
5. What are best practices for scripting error handling in patch management scripts?
Include try-catch blocks, logging, and retry mechanisms to handle failures gracefully and facilitate troubleshooting.
6. Is it possible to rollback updates if issues occur after deployment?
Yes, through Windows Update history and system restore points, but automation of rollback requires additional scripting and planning.