> For the complete documentation index, see [llms.txt](https://docs.realmjoin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmjoin.com/automation/runbooks/runbook-references/org/general/add-or-remove-safelinks-exclusion.md).

# Add Or Remove Safelinks Exclusion

Allow a URL pattern in a Safe Links policy or remove it

### Description

Adds a URL pattern to the exclusions of a Microsoft Defender Safe Links policy so links matching it are no longer rewritten, or removes such an exclusion. It can also list the existing policies with their settings, and create a policy with its assignment group when the requested one does not exist.

### Location

Organization → General → Add Or Remove Safelinks Exclusion

**Full Runbook name**

rjgit-org\_general\_add-or-remove-safeLinks-exclusion

### Details

| Property         | Value                                                                             |
| ---------------- | --------------------------------------------------------------------------------- |
| Version          | 1.0.2                                                                             |
| Required modules | <p>ExchangeOnlineManagement (>= 3.9.2)<br>RealmJoin.RunbookHelper (>= 0.8.10)</p> |
| Schedulable      | no                                                                                |

### Permissions

#### Application permissions

* **Type**: Office 365 Exchange Online
  * Exchange.ManageAsApp
    * *Manages Safe Links policies, rules and the assignment group in the app-only Exchange Online session*

#### RBAC roles

* Exchange Administrator
  * *Required for the app-only Exchange Online session updating DoNotRewriteUrls*

### Parameters

#### Action

Add puts the pattern on the exclusion list, Remove takes it off, List shows the policies and their settings.

| Property            | Value  |
| ------------------- | ------ |
| Required            | false  |
| Default Value       | 2      |
| Type                | Int32  |
| Portal display name | Action |

**Portal options**

| Portal option                           | Value |
| --------------------------------------- | ----- |
| Add URL pattern to policy               | 0     |
| Remove URL pattern from policy          | 1     |
| List all existing policies and settings | 2     |

#### LinkPattern

Pattern to exclude; \* works as a wildcard for host and path, for example https\://*.microsoft.com/*.

| Property      | Value                      |
| ------------- | -------------------------- |
| Required      | false                      |
| Default Value | https\://*.microsoft.com/* |
| Type          | String                     |

#### DefaultPolicyName

Policy used when no policy name is given.

| Property         | Value                                  |
| ---------------- | -------------------------------------- |
| Required         | true                                   |
| Default Value    | Default SafeLinks Policy               |
| Type             | String                                 |
| Hidden in portal | yes (preset via runbook customization) |

#### PolicyName

Policy to change. Leave empty to use the default policy.

| Property      | Value  |
| ------------- | ------ |
| Required      | false  |
| Default Value |        |
| Type          | String |

#### CreateNewPolicyIfNeeded

Creates the Safe Links policy and its assignment group when it does not exist yet.

| Property      | Value   |
| ------------- | ------- |
| Required      | false   |
| Default Value | True    |
| Type          | Boolean |

[Back to Runbook Reference overview](/automation/runbooks/runbook-references.md)


---

# 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.realmjoin.com/automation/runbooks/runbook-references/org/general/add-or-remove-safelinks-exclusion.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.
