簡體   English   中英

Microsoft Graph SDK (C#) 組郵箱

[英]Microsoft Graph SDK (C#) Group Mailbox

我正在編寫一個連接的控制台應用程序,以幫助自動化即將進行的租戶遷移。

我要做的是從我們當前的租戶中刪除自定義域的所有關聯,以便我可以將它們添加到新租戶。

到目前為止我所擁有的:

ConsoleApp 已向 AAD 注冊,並且已分配 API 權限並獲得同意。

我已經導入了以下內容:

using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client

初始化了一個graphClient

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

並成功對 Graph 進行了.GetAsync調用。

我需要幫助:

我正在嘗試將 Group 的 email 更新為'gItem.mailNickname@tenantID' 我有一個錯誤說“郵件字段是只讀的”。 通過 Graph Explorer,我注意到proxyAddresses字段包括該組的所有別名,並且郵件被列為“SMPT:...”我試圖用覆蓋proxyAddresses字段

var upGroup = await graphClient
    .Groups["4f629be4-f592-4520-b80d-7570f68e276e"]
    .Request()
    .GetAsync();

var updateFields = new Group
{
    ProxyAddresses = new List<string>()
    {
    "SMPT:" + upGroup.MailNickname + "@" + tenantID,
    }
};

await graphClient
    .Groups[upGroup.Id]
    .Request()
    .UpdateAsync(updateFields);

我收到權限不足的錯誤,但已檢查 AAD 以確保Directory.ReadWrite.AllGroups.ReadWrite.All均已配置和授予。

其他 Group 屬性可以更改,這導致我質疑proxyAddresses屬性的結構。

添加到列表中的代碼失敗

var updateFields = new Group
{
    ProxyAddresses = new string[] { "SMTP:" + upGroup.MailNickname + "@" + tenantID }
};

完整代碼:

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;

namespace RemoveGroupAliases
{

    class Program
    {
        private static string clientId = "";
        private static string tenantID = "";
        private static string clientSecret = "";
        private static IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
            .Create(clientId)
            .WithTenantId(tenantID)
            .WithClientSecret(clientSecret)
            .Build();

        static ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

        static async Task Main(string[] args)
        {
            GraphServiceClient graphClient = new GraphServiceClient(authProvider);

            var groups = await graphClient
                .Groups
                .Request()
                .Filter("mailEnabled+eq+true")
                .GetAsync();

            foreach (var tgroup in groups)
            {
                Console.WriteLine(tgroup.Id);
                Console.WriteLine(tgroup.DisplayName);
            };

            var upGroup = await graphClient
                .Groups["4f629be4-f592-4520-b80d-7570f68e276e"]
                .Request()
                .GetAsync();

            var updateFields = new Group
            {
                ProxyAddresses = new List<String>()
                {
                "SMTP:" + upGroup.MailNickname + "@" + tenantID
                }
            };

            await graphClient
                .Groups[upGroup.Id]
                .Request()
                .UpdateAsync(updateFields);

            Console.ReadLine();
        }
    }
}

這個想法是拉出所有啟用郵件的組並刪除所有域,以便我可以將其從該租戶中刪除並將其關聯到新租戶。 切換域后,我將有一個不同的程序來分配域和別名。 當我在proxyAddresses的工具提示上 hover 時,最后一行中的一行顯示“只讀”,這可能是我的問題,但我沒有將其視為錯誤。

你描述的場景根本不可能。 您不能從一個租戶中分離組(或實際上任何數據)並將其遷移到另一個租戶。 每個 AAD 租戶都是一個不同的實體,並且與任何其他租戶隔離。

Microsoft Graph 使用您提供的令牌將您的請求路由到生成令牌的租戶內的正確 API/服務。 您不能將單個令牌連接到多個租戶。

此外,如文檔中所述,屬性mailproxyAddresses是只讀的。 如果您希望更改組的 email 別名,您可以更改mailNickname屬性。 這只是組的“別名”,email 地址的域部分由 AAD 和 Exchange ( {mailNickname}@{default.tenant.domain} ) 自動分配。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM