> 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

Learn how to create a custom attribute script in Intune to collect specific information from managed macOS devices.

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 > By platform > macOS > Manage devices > Scripts. ![Custom Attribute](https://3465854426-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9BWB4smfcOeIGFw7Awl%2Fuploads%2Fgit-blob-4386910ac63d8d5c6a4aacf2beb85107e266482b%2Fcustom_attribute_1.png?alt=media)
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](https://3465854426-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9BWB4smfcOeIGFw7Awl%2Fuploads%2Fgit-blob-57df1940c2ba14460ffe27161df7e17d9ab0f1fa%2Fcustom_attribute_2.png?alt=media)
4. Upload the script and set the data type to "String". ![Custom Attribute](https://3465854426-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9BWB4smfcOeIGFw7Awl%2Fuploads%2Fgit-blob-64c9d34eb9dcc6d992e2cf844d262799d52eb5b6%2Fcustom_attribute_3.png?alt=media)
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](https://3465854426-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU9BWB4smfcOeIGFw7Awl%2Fuploads%2Fgit-blob-ceb0ef86f064e8cdb8dcffe8c2def3783cd85792%2Fcustom_attribute_4.png?alt=media)

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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
