import Global from '../../_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# graph openextension add

Adds an open extension to a resource

## Usage

```sh
m365 graph openextension add [options]
```

## Options

```md definition-list
`-n, --name <name>`
: The name of the open extension.

`-i, --resourceId <resourceId>`
: The Id of the resource for which the extension is created.

`-t, --resourceType <resourceType>`
: The resource type for which the extension is created. Allowed values are `user`, `group`, `device`, `organization`.
```

<Global />

## Remarks

This command allows using unknown options to add custom data to the open extension.

When adding an open extension to a user, it's possible to use the UPN as the resourceId.

:::warning[Escaping JSON in PowerShell]

When creating open extensions it's possible to enter a JSON string. In PowerShell 5 to 7.2 [specific escaping rules](./../../../user-guide/using-cli.mdx#escaping-double-quotes-in-powershell) apply due to an issue. Remember that you can also use [file tokens](./../../../user-guide/using-cli.mdx#passing-complex-content-into-cli-options) instead.

:::

## Permissions
<Tabs>
  <TabItem value="Delegated">

  | Resource        | Permissions                                                                                 |
  |-----------------|---------------------------------------------------------------------------------------------|
  | Microsoft Graph | Directory.AccessAsUser.All, Group.ReadWrite.All, Organization.ReadWrite.All, User.ReadWrite |

  </TabItem>
  <TabItem value="Application">

  | Resource        | Permissions                                                                               |
  |-----------------|-------------------------------------------------------------------------------------------|
  | Microsoft Graph | Device.ReadWrite.All, Group.ReadWrite.All, Organization.ReadWrite.All, User.ReadWrite.All |

  </TabItem>
</Tabs>

## Examples

Create a new open extension for a user specified by id. Extension properties are specified by unknown options.

```sh
m365 graph openextension add --resourceId eb77fbcf-6fe8-458b-985d-1747284793bc --resourceType user --name 'com.contoso.roamingSettings' --theme dark --color red --language English
```

Create a new open extension for a user specified by userName. Extension properties are specified by unknown options.

```sh
m365 graph openextension add --resourceId adelev@contoso.com --resourceType user --name 'com.contoso.roamingSettings' --theme dark --color red --language English
```

Create a new open extension for a group, one of the property represents a JSON object

```sh
m365 graph openextension add --resourceId eb77fbcf-6fe8-458b-985d-1747284793bc --resourceType group --name 'com.contoso.roamingSettings' --settings '{"theme": "dark", "color": "red", "language": "English"}' --supportedSystem 'Linux'
```

## Response

<Tabs>
  <TabItem value="JSON">

  ```json
  {
    "extensionName": "com.contoso.roamingSettings",
    "settings": {
      "theme": "dark",
      "color": "red",
      "language": "English"
    },
    "supportedSystem": "Linux",
    "id": "com.contoso.roamingSettings"
  }
  ```

  </TabItem>
  <TabItem value="Text">

  ```text
  extensionName  : com.contoso.roamingSettings
  id             : com.contoso.roamingSettings
  settings       : {"theme":"dark","color":"red","language":"English"}
  supportedSystem: Linux
  ```

  </TabItem>
  <TabItem value="CSV">

  ```csv
  extensionName,supportedSystem,id
  com.contoso.roamingSettings,Linux,com.contoso.roamingSettings
  ```

  </TabItem>
  <TabItem value="Markdown">

  ```md
  # graph openextension add --name "com.contoso.roamingSettings" --resourceId "01b62bc5-9701-4f93-9587-9d1ea58a086d" --resourceType "user" --settings "{"theme": "dark", "color": "red", "language": "English"}" --supportedSystem "Linux"

  Date: 3/13/2025

  ## com.contoso.roamingSettings

  Property | Value
  ---------|-------
  extensionName | com.contoso.roamingSettings
  supportedSystem | Linux
  id | com.contoso.roamingSettings
  ```

  </TabItem>
</Tabs>

## More information

- Open extensions: https://learn.microsoft.com/graph/api/opentypeextension-post-opentypeextension
