命名空间:microsoft.graph
基于 groupSettingTemplates 中可用的模板创建新设置。 这些设置可以位于租户级别或组级别。
组设置仅适用于Microsoft 365 个组。 名为 的 Group.Unified
模板可用于配置租户范围的Microsoft 365 组设置,而名为 的 Group.Unified.Guest
模板可用于配置组特定的设置。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Directory.ReadWrite.All |
不可用。 |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
Directory.ReadWrite.All |
不可用。 |
重要
在具有工作或学校帐户的委托方案中,必须为登录用户分配受支持的Microsoft Entra角色或具有支持的角色权限的自定义角色。 此操作支持以下最低特权角色。
- 读取有关设置模板和设置的基本属性 - Microsoft Entra加入的设备本地管理员、目录读取器、全局读取器
- 管理所有组/目录设置 - 目录编写器
- 管理组的全局和本地设置;管理和
Group.Unified.Guest
Group.Unified
设置 - 组管理员
- 更新
Password Rule Settings
- 身份验证策略管理员
- 更新设置,读取有关设置模板和设置的基本属性 - 用户管理员
HTTP 请求
创建租户范围的设置。
POST /groupSettings
创建组特定的设置。
POST /groups/{id}/settings
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-Type |
application/json |
请求正文
在请求正文中,提供 groupSetting 对象的 JSON 表示形式。 显示名称、templateId 和说明继承自引用的 groupSettingTemplates 对象。 只能更改默认值的值属性。
创建 groupSetting 对象时需要以下属性。
响应
如果成功,此方法将在响应正文中返回 201 Created
响应代码和 groupSetting 对象。
示例 1:为租户中所有Microsoft 365 个组创建新设置
请求
只有名为 Group.Unified
的 groupSettingTemplates 对象可以应用于租户级别的所有Microsoft 365 个组。
POST https://graph.microsoft.com/v1.0/groupSettings
Content-type: application/json
{
"templateId": "62375ab9-6b52-47ed-826b-58e47e0e304b",
"values": [
{
"name": "GuestUsageGuidelinesUrl",
"value": "https://privacy.contoso.com/privacystatement"
},
{
"name": "EnableMSStandardBlockedWords",
"value": "true"
},
{
"name": "EnableMIPLabels",
"value": "true"
},
{
"name": "PrefixSuffixNamingRequirement",
"value": "[Contoso-][GroupName]"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new GroupSetting
{
TemplateId = "62375ab9-6b52-47ed-826b-58e47e0e304b",
Values = new List<SettingValue>
{
new SettingValue
{
Name = "GuestUsageGuidelinesUrl",
Value = "https://privacy.contoso.com/privacystatement",
},
new SettingValue
{
Name = "EnableMSStandardBlockedWords",
Value = "true",
},
new SettingValue
{
Name = "EnableMIPLabels",
Value = "true",
},
new SettingValue
{
Name = "PrefixSuffixNamingRequirement",
Value = "[Contoso-][GroupName]",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.GroupSettings.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc group-settings create --body '{\
"templateId": "62375ab9-6b52-47ed-826b-58e47e0e304b",\
"values": [\
{\
"name": "GuestUsageGuidelinesUrl",\
"value": "https://privacy.contoso.com/privacystatement"\
},\
{\
"name": "EnableMSStandardBlockedWords",\
"value": "true"\
},\
{\
"name": "EnableMIPLabels",\
"value": "true"\
},\
{\
"name": "PrefixSuffixNamingRequirement",\
"value": "[Contoso-][GroupName]"\
}\
]\
}\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewGroupSetting()
templateId := "62375ab9-6b52-47ed-826b-58e47e0e304b"
requestBody.SetTemplateId(&templateId)
settingValue := graphmodels.NewSettingValue()
name := "GuestUsageGuidelinesUrl"
settingValue.SetName(&name)
value := "https://privacy.contoso.com/privacystatement"
settingValue.SetValue(&value)
settingValue1 := graphmodels.NewSettingValue()
name := "EnableMSStandardBlockedWords"
settingValue1.SetName(&name)
value := "true"
settingValue1.SetValue(&value)
settingValue2 := graphmodels.NewSettingValue()
name := "EnableMIPLabels"
settingValue2.SetName(&name)
value := "true"
settingValue2.SetValue(&value)
settingValue3 := graphmodels.NewSettingValue()
name := "PrefixSuffixNamingRequirement"
settingValue3.SetName(&name)
value := "[Contoso-][GroupName]"
settingValue3.SetValue(&value)
values := []graphmodels.SettingValueable {
settingValue,
settingValue1,
settingValue2,
settingValue3,
}
requestBody.SetValues(values)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
groupSettings, err := graphClient.GroupSettings().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
GroupSetting groupSetting = new GroupSetting();
groupSetting.setTemplateId("62375ab9-6b52-47ed-826b-58e47e0e304b");
LinkedList<SettingValue> values = new LinkedList<SettingValue>();
SettingValue settingValue = new SettingValue();
settingValue.setName("GuestUsageGuidelinesUrl");
settingValue.setValue("https://privacy.contoso.com/privacystatement");
values.add(settingValue);
SettingValue settingValue1 = new SettingValue();
settingValue1.setName("EnableMSStandardBlockedWords");
settingValue1.setValue("true");
values.add(settingValue1);
SettingValue settingValue2 = new SettingValue();
settingValue2.setName("EnableMIPLabels");
settingValue2.setValue("true");
values.add(settingValue2);
SettingValue settingValue3 = new SettingValue();
settingValue3.setName("PrefixSuffixNamingRequirement");
settingValue3.setValue("[Contoso-][GroupName]");
values.add(settingValue3);
groupSetting.setValues(values);
GroupSetting result = graphClient.groupSettings().post(groupSetting);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const groupSetting = {
templateId: '62375ab9-6b52-47ed-826b-58e47e0e304b',
values: [
{
name: 'GuestUsageGuidelinesUrl',
value: 'https://privacy.contoso.com/privacystatement'
},
{
name: 'EnableMSStandardBlockedWords',
value: 'true'
},
{
name: 'EnableMIPLabels',
value: 'true'
},
{
name: 'PrefixSuffixNamingRequirement',
value: '[Contoso-][GroupName]'
}
]
};
await client.api('/groupSettings')
.post(groupSetting);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\GroupSetting;
use Microsoft\Graph\Generated\Models\SettingValue;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new GroupSetting();
$requestBody->setTemplateId('62375ab9-6b52-47ed-826b-58e47e0e304b');
$valuesSettingValue1 = new SettingValue();
$valuesSettingValue1->setName('GuestUsageGuidelinesUrl');
$valuesSettingValue1->setValue('https://privacy.contoso.com/privacystatement');
$valuesArray []= $valuesSettingValue1;
$valuesSettingValue2 = new SettingValue();
$valuesSettingValue2->setName('EnableMSStandardBlockedWords');
$valuesSettingValue2->setValue('true');
$valuesArray []= $valuesSettingValue2;
$valuesSettingValue3 = new SettingValue();
$valuesSettingValue3->setName('EnableMIPLabels');
$valuesSettingValue3->setValue('true');
$valuesArray []= $valuesSettingValue3;
$valuesSettingValue4 = new SettingValue();
$valuesSettingValue4->setName('PrefixSuffixNamingRequirement');
$valuesSettingValue4->setValue('[Contoso-][GroupName]');
$valuesArray []= $valuesSettingValue4;
$requestBody->setValues($valuesArray);
$result = $graphServiceClient->groupSettings()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.group_setting import GroupSetting
from msgraph.generated.models.setting_value import SettingValue
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = GroupSetting(
template_id = "62375ab9-6b52-47ed-826b-58e47e0e304b",
values = [
SettingValue(
name = "GuestUsageGuidelinesUrl",
value = "https://privacy.contoso.com/privacystatement",
),
SettingValue(
name = "EnableMSStandardBlockedWords",
value = "true",
),
SettingValue(
name = "EnableMIPLabels",
value = "true",
),
SettingValue(
name = "PrefixSuffixNamingRequirement",
value = "[Contoso-][GroupName]",
),
],
)
result = await graph_client.group_settings.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groupSettings/$entity",
"id": "844d252c-4de2-43eb-a784-96df77231aae",
"displayName": null,
"templateId": "62375ab9-6b52-47ed-826b-58e47e0e304b",
"values": [
{
"name": "GuestUsageGuidelinesUrl",
"value": "https://privacy.contoso.com/privacystatement"
},
{
"name": "EnableMSStandardBlockedWords",
"value": "true"
},
{
"name": "EnableMIPLabels",
"value": "true"
},
{
"name": "PrefixSuffixNamingRequirement",
"value": "[Contoso-][GroupName]"
}
]
}
displayName 属性和其他名称/值对将填充与 templateId 匹配的 groupSettingTemplates 对象的默认值。
示例 2:创建设置以阻止特定Microsoft 365 组的来宾
请求
只有名为 Group.Unified.Guest
的 groupSettingTemplates 对象可以应用于 365 个组的特定Microsoft。
POST https://graph.microsoft.com/v1.0/groups/055a5d18-a3a9-4338-b9c5-de92559b7ebf/settings
Content-type: application/json
{
"templateId": "08d542b9-071f-4e16-94b0-74abb372e3d9",
"values": [
{
"name": "AllowToAddGuests",
"value": "false"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new GroupSetting
{
TemplateId = "08d542b9-071f-4e16-94b0-74abb372e3d9",
Values = new List<SettingValue>
{
new SettingValue
{
Name = "AllowToAddGuests",
Value = "false",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].Settings.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc groups settings create --group-id {group-id} --body '{\
"templateId": "08d542b9-071f-4e16-94b0-74abb372e3d9",\
"values": [\
{\
"name": "AllowToAddGuests",\
"value": "false"\
}\
]\
}\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewGroupSetting()
templateId := "08d542b9-071f-4e16-94b0-74abb372e3d9"
requestBody.SetTemplateId(&templateId)
settingValue := graphmodels.NewSettingValue()
name := "AllowToAddGuests"
settingValue.SetName(&name)
value := "false"
settingValue.SetValue(&value)
values := []graphmodels.SettingValueable {
settingValue,
}
requestBody.SetValues(values)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
settings, err := graphClient.Groups().ByGroupId("group-id").Settings().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
GroupSetting groupSetting = new GroupSetting();
groupSetting.setTemplateId("08d542b9-071f-4e16-94b0-74abb372e3d9");
LinkedList<SettingValue> values = new LinkedList<SettingValue>();
SettingValue settingValue = new SettingValue();
settingValue.setName("AllowToAddGuests");
settingValue.setValue("false");
values.add(settingValue);
groupSetting.setValues(values);
GroupSetting result = graphClient.groups().byGroupId("{group-id}").settings().post(groupSetting);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const groupSetting = {
templateId: '08d542b9-071f-4e16-94b0-74abb372e3d9',
values: [
{
name: 'AllowToAddGuests',
value: 'false'
}
]
};
await client.api('/groups/055a5d18-a3a9-4338-b9c5-de92559b7ebf/settings')
.post(groupSetting);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\GroupSetting;
use Microsoft\Graph\Generated\Models\SettingValue;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new GroupSetting();
$requestBody->setTemplateId('08d542b9-071f-4e16-94b0-74abb372e3d9');
$valuesSettingValue1 = new SettingValue();
$valuesSettingValue1->setName('AllowToAddGuests');
$valuesSettingValue1->setValue('false');
$valuesArray []= $valuesSettingValue1;
$requestBody->setValues($valuesArray);
$result = $graphServiceClient->groups()->byGroupId('group-id')->settings()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Groups
$params = @{
templateId = "08d542b9-071f-4e16-94b0-74abb372e3d9"
values = @(
@{
name = "AllowToAddGuests"
value = "false"
}
)
}
New-MgGroupSetting -GroupId $groupId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.group_setting import GroupSetting
from msgraph.generated.models.setting_value import SettingValue
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = GroupSetting(
template_id = "08d542b9-071f-4e16-94b0-74abb372e3d9",
values = [
SettingValue(
name = "AllowToAddGuests",
value = "false",
),
],
)
result = await graph_client.groups.by_group_id('group-id').settings.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
在请求正文中,提供 groupSetting 对象的 JSON 表示形式。
响应
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groupSettings/$entity",
"id": "a06fa228-3042-4662-bd09-33e298da1afe",
"displayName": null,
"templateId": "08d542b9-071f-4e16-94b0-74abb372e3d9",
"values": [
{
"name": "AllowToAddGuests",
"value": "false"
}
]
}