> ## Documentation Index
> Fetch the complete documentation index at: https://docs.iru.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom Scripts Overview

> Deploy custom scripts to managed Mac and Windows computers using Iru Endpoint. Run shell, Python, PowerShell, or batch scripts on enrollment or on schedule.

Custom Scripts are available for Mac computers and Windows computers

### What is a Custom Script?

Custom scripts in Iru Endpoint automate tasks and configure settings on managed devices. Think of them as a set of instructions that can be deployed and executed on enrolled devices using the Iru Agent. With custom scripts, you can configure device settings, install or update software applications, run maintenance tasks, and enforce security policies. You can also use custom scripts to collect device information, like hardware inventory or system logs. A collection of prebuilt and regularly maintained scripts is available in our [GitHub repository](https://github.com/kandji-inc/support/tree/main/Scripts).

> [tab] Mac
>
> > [!NOTE]
> >
> > Iru Endpoint's Custom Script Library Item can deploy scripts in various languages. However, our support team is best equipped to help troubleshoot scripts written in shell, bash, zshell, or Python. Support can also assist with AppleScript, provided it is invoked by one of the supported languages.
>
> ### How Custom Scripts Work
>
> The Iru Agent runs custom scripts on enrolled Mac computers. Your custom script can specify any shell or interpreter on the Mac computer. If a shell or interpreter is not specified, the default shell (/bin/sh) is used. Custom scripts are always executed as the root user.
>
> #### Execution Frequency
>
> Depending on the script you want to deploy, you can specify whether it will be run once at every check-in, once per day, or on-demand from Self Service.
>
> > [accordion] Install once per device
> >
> > For **Install once per device**, Iru reruns the audit script at each check-in until the Library Item reaches **Pass** for that device. If a remediation script is enabled and succeeds, the Library Item can show **Remediated**, but Iru still reruns the audit script on later check-ins until it reaches **Pass**.
>
> > [accordion] Run every 15 min
> >
> > The script will be run at each check-in (\~ every 15 minutes).
>
> > [accordion] Run daily
> >
> > The script will be run every 24 hours based on the previous run time.
>
> > [accordion] Run on-demand from Self Service
> >
> > The script will never be run automatically and will only be offered as an optional item from Self Service. After executing the item, the **Run** button will be relabelled **Run again**.
>
> The Custom Script Library Item can also be offered via Self Service in the first 3 scenarios above.
>
> #### Exit Codes and Outputs
>
> > [accordion] Exit code results
> >
> > If the audit script exits with code **0**, that run has **Pass** status. If the audit script exits with any non-zero exit code, that run has **Error** status. When a run has **Error** status, Iru generates an alert. See our [Global Alerts](https://docs.iru.com/en/endpoint/devices/global-alerts.md) support article for details.
>
> > [accordion] Script output logging
> >
> > Stdout and Stderr are recorded in the script's audit information, which can be found on the device status page or custom script status page.
>
> #### Remediation
>
> A remediation script allows the main **Audit Script** to be used as a true audit script to check for system configuration or application state. If the audit script exits with any non-zero exit code, that run has **Error** status; Iru then runs the remediation script.
>
> > [!TIP]
> >
> > If the remediation script exits with code **0**, the Library Item status for that device is **Remediated**. If the remediation script exits with a non-zero exit code, the Library Item status for that device is **Error**, and Iru generates an alert. See our [Global Alerts](https://docs.iru.com/en/endpoint/devices/global-alerts.md) support article for details.
>
> #### Restart Options
>
> The restart option allows you to force a restart after a successful script execution. When selecting this option, the user will receive a restart timer from the Iru Agent menu bar application. This timer will be a 5-minute restart timer if the item was initiated from Self Service or a 30-minute restart timer if initiated in another way such as during a check-in.
>
> > [!TIP]
> >
> > The restart option will behave differently based on the use of a remediation script:
> >
> > * If a [**Remediation** script](#remediation) is being used, when the **Remediation** script exits 0, this will trigger the restart countdown.
> > * If a **Remediation** script *is not* being used, when the **Audit** script exits 0, this will trigger the restart countdown.
>
> #### Liftoff Settings
>
> At the bottom of the Custom Script, expand **Liftoff Settings**. There you will find **Process this Library Item**. This setting chooses when the script is installed relative to [Iru Liftoff](https://docs.iru.com/en/endpoint/library/library-items-profiles/configure-the-liftoff-library-item.md). It applies to Automated Device Enrollment and manual enrollment.
>
> * **During Liftoff** (default): The Custom Script processes during Liftoff, and Liftoff does not complete until it finishes. It appears on the Install screen unless **Hide in Liftoff** is selected.
>   * **Hide in Liftoff**: If selected, this Library Item still processes during Liftoff but is not shown on the Install screen. While it processes, Liftoff shows **Processing additional required configurations before proceeding…** at the bottom of the screen. This setting does not affect ordering.
>   * **Friendly name** (optional): If specified, Liftoff shows this name instead of the Library Item **Name**. The Iru Agent still orders Library Items by **Name** during check-in.
>
> * **After Liftoff**: The Custom Script does not process during Liftoff and does not appear on the Install screen. It installs on a later agent check-in.
>
> > [!NOTE]
> >
> > If this Custom Script is also included in **Install Library Items during Setup Assistant** on the [Automated Device Enrollment Library Item](https://docs.iru.com/en/endpoint/enrollment/apple/configuring-apple-enrollment.md#install-library-items-during-setup-assistant), it still installs during Setup Assistant. **Process this Library Item** does not change that install.
>
> ### Add a Custom Script Library Item
>
> To add this Library Item to your Iru Endpoint Library, follow the steps outlined in the [Library Overview](https://docs.iru.com/en/endpoint/library/library-items-profiles/library-overview.md) article.
>
> **1. Name the Library Item**
>
> Give the new Custom Script Library Item a **Name**.
>
> **2. Assign to Blueprints**
>
> Assign to your desired [Blueprints](https://docs.iru.com/en/endpoint/getting-started/blueprints-and-library/configuring-blueprints.md).
>
> **3. Select Execution Frequency**
>
> Select an **Execution Frequency**.
>
> **4. Configure Self Service (optional)**
>
> Optionally, make the script available in **Self Service**.
>
> **5. Add Audit Script**
>
> Paste your script into the **Audit Script** field.
>
> **6. Add Remediation Script (optional)**
>
> Optionally, configure and paste a **Remediation Script**.
>
> **7. Configure restart option (optional)**
>
> If desired, check the box to **Restart after a successful execution**.
>
> **8. Configure Liftoff Settings (optional)**
>
> Expand **Liftoff Settings**. **Process this Library Item** defaults to **During Liftoff**. To install the script after Liftoff finishes, select **After Liftoff**. See [Liftoff Settings](#liftoff-settings).
>
> **9. Save configuration**
>
> Select **Save**.
>
> ### Related Articles
>
> > [card] [Library Overview](https://docs.iru.com/en/endpoint/library/library-items-profiles/library-overview.md)
> >
> > Curate, create, and manage Library Items and add them to Blueprints
>
> > [card] [Configuring Blueprints](https://docs.iru.com/en/endpoint/getting-started/blueprints-and-library/configuring-blueprints.md)
> >
> > Create and configure device Blueprints for policy management
>
> > [card] [Deploy Homebrew Using a Custom Script](https://docs.iru.com/en/endpoint/library/deployment-guides/apple/deploy-homebrew-using-a-custom-script.md)
> >
> > Deploy Homebrew to Mac computers using a custom script
>
> > [card] [Global Variables](https://docs.iru.com/en/endpoint/library/library-items-profiles/global-variables.md)
> >
> > Learn how to use global variables in Iru Endpoint to dynamically insert device and user information into profiles, scripts, and configuration settings.
>
> > [card] [Global Alerts](https://docs.iru.com/en/endpoint/devices/global-alerts.md)
> >
> > Configure how Iru Endpoint surfaces alerts when Custom Scripts or other Library Items report issues

> [tab] Windows
>
> ### Windows Custom Script
>
> The **Windows custom script** Library Item allows you to run PowerShell scripts on managed Windows computers. You can use this item to audit device state, enforce configuration through remediation, or perform administrative tasks not covered by built-in Windows profiles.
>
> Windows custom scripts support an audit and remediation model, enabling detection of non-compliant states and automatically correcting them.
>
> ### Create a Windows Custom Scripts Library Item
>
> **1. Navigate to Library**
>
> Navigate to **Library**.
>
> **2. Add Library Item**
>
> Select **Add Library Item**.
>
> **3. Select Windows Custom Script**
>
> Search for and select **Windows Custom Script**.
>
> **4. Enter Name**
>
> Enter a descriptive **Name**.
>
> **5. Confirm Status**
>
> Confirm the status is set to **Active**.
>
> **6. Assign to Blueprints**
>
> Assign the Library Item to one or more **Blueprints**.
>
> ### Script Details
>
> The **Script details** section defines settings for audit and remediation scripts.
>
> #### Audit Script
>
> The **Audit script** determines whether the device is in the desired state.
>
> You can provide the audit script using one of the following options:
>
> * **Upload signed script**
>   * Upload a signed PowerShell `.ps1` file.
> * **Manually enter script**
>   * Paste or edit PowerShell code directly into the editor.
>
> > [!NOTE]
> >
> > The audit script should exit with a non-zero exit code when the device is not compliant. A zero exit code indicates compliance.
>
> #### Command Line Parameters (Optional)
>
> The **Command line parameters** field allows you to pass arguments to the audit and remediation scripts at runtime.
>
> * Use standard PowerShell parameter syntax.
> * Parameters are appended when the script executes.
>
> Example: `-Mode Full -ConfigPath "C:\Config.json"`
>
> > [!TIP]
> >
> > This is useful for making scripts reusable without hardcoding values.
>
> #### Remediation Script (Optional)
>
> Select **Add remediation script** to configure a remediation action.
>
> * The remediation script runs only when the audit script reports non-compliance.
>
> * You can upload a signed script or manually enter remediation logic.
>
> * Use remediation scripts to correct configuration drift or enforce settings.
>
> > [!NOTE]
> >
> > The remediation script should exit successfully after the issue is resolved.
>
> #### Execute In
>
> Use **Execute in** to select the PowerShell environment used to run the scripts:
>
> * **64 bit**
> * **32 bit**
>
> **64 bit** runs the script in the standard 64-bit PowerShell environment and is recommended for most Windows computers.
>
> > [!NOTE]
> >
> > Use 32 bit only if the script or its dependencies require WOW64 compatibility.
>
> ### Assignment and Execution
>
> After saving the Library Item:
>
> 1. Select **Save**.
> 2. Assign it to one or more **Blueprints** using **+ Assign**.
>
> Scripts will execute once per device.
>
> ### Best Practices
>
> * Sign PowerShell scripts before uploading whenever possible.
> * Separate detection logic (audit) from enforcement logic (remediation).
> * Test scripts on non-production devices before wide deployment.
>
> ### Related Articles
>
> > [card] [Microsoft PowerShell Documentation](https://learn.microsoft.com/powershell/)
> >
> > Official PowerShell docs from Microsoft
>
> > [card] [Everything about exceptions (PowerShell)](https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-exceptions)
> >
> > PowerShell exception handling
>
> > [card] [Global Alerts](https://docs.iru.com/en/endpoint/devices/global-alerts.md)
> >
> > Configure how Iru Endpoint surfaces alerts when Windows Custom Scripts or other Library Items report issues


## Related topics

- [Library Overview](https://docs.iru.com/en/endpoint/library/library-items-profiles/library-overview.md)
- [Deploy Homebrew Using a Custom Script](https://docs.iru.com/en/endpoint/library/deployment-guides/apple/deploy-homebrew-using-a-custom-script.md)
- [Configure the Liftoff Library Item](https://docs.iru.com/en/endpoint/library/library-items-profiles/configure-the-liftoff-library-item.md)
