> For the complete documentation index, see [llms.txt](https://docs.intunemacadmins.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.intunemacadmins.com/custom-attributes/create-custom-attributes.md).

# Create a Custom Attribute Script

Custom attributes in Intune allow you to collect specific information from managed macOS devices using shell scripts. One useful application is to retrieve the last reboot time of a device. This can be valuable for troubleshooting, maintenance scheduling, or ensuring compliance with reboot policies.

### Last Reboot Time Script

To get the last reboot time of macOS devices, you can use the following shell script:

```bash
#!/bin/bash
# Script to get the last reboot time formatted

# Extracting the timestamp from the sysctl command
timestamp=$(sysctl kern.boottime | awk '{print $5}' | tr -d ',')

# Converting the timestamp to a formatted date
formatted_date=$(date -r $timestamp "+%Y-%m-%d %H:%M:%S")

echo "Last Reboot Time: $formatted_date"
```

This script does the following:

1. Extracts the boot timestamp using the `sysctl` command.
2. Processes the timestamp with `awk` and `tr` to clean up the output.
3. Converts the timestamp to a human-readable date format.
4. Outputs the formatted last reboot time.

### Configuring the Custom Attribute

To use this script as a custom attribute in Intune:

1. Go to the Intune portal and navigate to Devices > macOS > Custom Attributes. ![Custom Attribute](/files/qdS3tH6jGeCowPo4uwzH)
2. Click on "+ Add" to create a new custom attribute.
3. Provide a name (e.g., "Last Reboot Time") and description for the attribute. ![Custom Attribute](/files/VyBGJDAqY9YyPxcDCFdJ)
4. Upload the script and set the data type to "String". ![Custom Attribute](/files/KLRdJHyquuTBWJrtuQPr)
5. Assign the custom attribute to the devices you want to collect the data from.

After configuration, Intune will run this script on the targeted devices and collect the last reboot time information. You can then view this data in the Intune portal or use it for reporting and compliance purposes.

{% hint style="info" %}
Custom Attributes run every 8 hours by default. You can not change the frequency of the script and you can not run it on-demand.
{% endhint %}

### Viewing Results

Once the custom attribute is deployed and executed on the devices, you can view the results by:

1. Going to the Intune portal and selecting a macOS device.
2. Navigating to the "Custom Attributes" section.
3. Looking for the "Last Reboot Time" attribute in the list. ![Custom Attribute](/files/CmqookiuzxemMQFkb0QI)

The result will show the last reboot time of the device in the format: "YYYY-MM-DD HH:MM:SS".

By implementing this custom attribute, you gain valuable insights into the uptime of your managed macOS devices, helping you maintain a more secure and efficient IT environment.

[Learn more about custom attributes for macOS in Intune](https://ugurkoc.de/get-local-admins-and-last-reboot-time-on-macos-devices-using-custom-attributes/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.intunemacadmins.com/custom-attributes/create-custom-attributes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
