Deploying a Script through Intune to a Linux PC
Can Intune Deploy Shell Scripts to Linux Devices? Yes!
Just like deploying PowerShell scripts to Windows, Intune can also deploy shell scripts to Linux devices. In this blog, I'll walk you through the process of deploying shell scripts to Linux using Intune, making it easier to automate tasks and manage Linux endpoints efficiently.
Prerequisites
Before deploying a shell script via Intune, ensure the following requirements are met:
1. Intune and Microsoft Entra ID
Your environment must have Microsoft Intune configured for device management. This setup enables secure enrollment and policy enforcement on Linux devices.
2. Linux Device Enrollment
The Linux PC must be properly enrolled in Intune to receive policies and scripts. If the device is not enrolled, follow Microsoft's documentation on Linux enrollment in Intune.
Deploying the Shell Script
Once the prerequisites are met, follow these steps to deploy your shell script through Intune:
Access Microsoft Intune
Sign in to the https://intune.microsoft.com/
Navigate to the Devices pane.
Select Linux Management
Under Devices, locate and select Linux.
Add a New Script
Click on Scripts and select Add.
Then, add the script and give a name
Fill in the details as
required and save your shell script with a .sh extension.
I used the following shell script
for testing:
bash
CopyEdit
#!/bin/bash
# Define the cron job
CRON_JOB="* * * * *
logger \"Test Intune\""
# Check if the cron job already exists
(crontab -l 2>/dev/null |
grep -F "$CRON_JOB") || (crontab -l 2>/dev/null; echo "$CRON_JOB")
| crontab -
echo "Cron job deployed successfully."
This script ensures that the cron
job runs every minute, with the logger "Test Intune" command logging
the message "Test Intune" to the system log each time it runs.
When you upload it , in bash script pane automatically fills with the script.
Then select assignment
Select the group that includes linux devices
Now it has finished and profile has created.
Now you can monitor the status after some time.
Select the script
Now you can see the script has been successfully initiated.
We'll check from the Ubuntu PC to
ensure that the script has run.
The cron job has been created and
is working.
The cron job has been created and is working.