共用方式為


快速入門:使用 .NET SDK 建立 Microsoft Purview (先前稱為 Azure Purview) 帳戶

注意事項

Microsoft Purview 資料目錄 (傳統) 和 Data Health Insights (傳統) 不再接受新客戶,而且這些服務 (先前為 Azure Purview) 現在處於客戶支援模式。

重要事項

每個租用戶只能建立一個 Microsoft Purview 帳戶。 如果您的組織已經有 Microsoft Purview 帳戶,除非您的組織已經有多個帳戶,而且仍低於 預先存在的配額,否則您將無法建立新的 Microsoft Purview 帳戶。 如需詳細資訊,請參閱 常見問題集

在本快速入門中,您將使用 .NET SDK 來建立 Microsoft Purview (先前稱為 Azure Purview) 帳戶。

Microsoft Purview 治理入口網站會顯示 Microsoft Purview 資料對應和 Microsoft Purview 資料目錄等工具,可協助您管理和控管資料環境。 透過連線到內部部署、多雲端和軟體即服務 (SaaS) 來源的資料,Microsoft Purview 資料對應會建立最新的資訊對應。 它識別和分類敏感資料,並提供端對端譜系。 資料取用者能夠探索整個組織的資料,而資料管理員能夠稽核、保護和確保正確使用您的資料。

如需 Microsoft Purview 傳統治理功能的詳細資訊, 請參閱我們的治理解決方案概觀頁面

必要條件

  • 如果您沒有 Azure 訂用帳戶,請先建立 免費訂用帳戶 ,再開始。

  • 與您的訂用帳戶相關聯的 Microsoft Entra 租用戶

  • 您用來登入 Azure 的使用者帳戶必須是 參與者擁有者 角色的成員,或 Azure 訂用帳戶的 系統管理員 。 若要檢視您在訂用帳戶中擁有的權限,請遵循下列步驟:

    1. 移至 Azure 入口網站
    2. 在右上角選擇您的用戶名。
    3. 選取省略符號按鈕 (“...”) 更多選擇。
    4. 然後選取 [我的許可權]。
    5. 如果您有權存取多個訂用帳戶,請選取適當的訂用帳戶。

登入 Azure

使用您的 Azure 入口網站 登入您的 Azure 帳戶。

Visual Studio

本文中的逐步解說會使用 Visual Studio 2019。 Visual Studio 2013、2015 或 2017 的程式可能會略有不同。

Azure .NET SDK

在您的電腦上下載並安裝 Azure .NET SDK

在 Microsoft Entra ID 中建立應用程式

  1. 建立 Microsoft Entra 應用程式中,建立代表您在本教學課程中建立的 .NET 應用程式的應用程式。 對於登入 URL,您可以提供虛擬 URL,如) (https://contoso.org/exampleapp 一文所示。
  2. 在 [ 取得登入的值] 中,取得 應用程式識別碼租用戶識別碼,並記下您稍後在本教學課程中使用的這些值。
  3. [憑證和密碼] 中,取得 驗證金鑰,並記下您稍後在本教學課程中使用的此值。
  4. 將應用程式指派給角色 中,將應用程式指派給訂閱層次 的 參與者 角色 ,以便應用程式可以在訂閱中建立 Data Factory。

建立 Visual Studio 專案

接下來,在 Visual Studio 中建立 C# .NET 主控台應用程式:

  1. 啟動 Visual Studio
  2. 在「開始」視窗中,選取「建立新的專案>主控台應用程式 (.NET Framework) 」。 需要 .NET 4.5.2 版或更高版本。
  3. [專案名稱] 中,輸入 PurviewQuickStart
  4. 選取 [建立] 以建立專案。

安裝 NuGet 套件

  1. 選取 [ 工具] [>NuGet 套件管理員>] [套件管理員] [主控台]。

  2. [套件管理員主控台] 窗格中,執行下列命令來安裝套件。 如需詳細資訊,請參閱 Microsoft.Azure.Management.Purview NuGet 套件

    Install-Package Microsoft.Azure.Management.Purview
    Install-Package Microsoft.Azure.Management.ResourceManager -IncludePrerelease
    Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory
    

提示

如果您收到錯誤,內容為:在 下列主要來源中找不到套件 <套件名稱> , (的) : ,而且它會列出本機資料夾,您必須在 Visual Studio 中更新套件來源,以將 nuget 網站包含在線上來源中。

  1. 前往 工具
  2. 選取 [NuGet 套件管理員]
  3. 選取 [套件管理設定]
  4. 選取 套件來源
  5. 新增 https://nuget.org/api/v2/ 為來源。

建立 Microsoft Purview 用戶端

  1. 開啟 Program.cs,包含下列陳述式,以新增命名空間的參照。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Rest;
    using Microsoft.Rest.Serialization;
       using Microsoft.Azure.Management.ResourceManager;
    using Microsoft.Azure.Management.Purview;
       using Microsoft.Azure.Management.Purview.Models;
       using Microsoft.IdentityModel.Clients.ActiveDirectory;
    
  2. 將下列程式碼新增至設定變數的 Main 方法。 將預留位置取代為您自己的值。 如需目前提供 Microsoft Purview 的 Azure 區域清單,請在 Microsoft Purview 上搜尋,並在下列頁面上選取您感興趣的區域: 依區域提供的產品

    // Set variables
    string tenantID = "<your tenant ID>";
    string applicationId = "<your application ID>";
    string authenticationKey = "<your authentication key for the application>";
    string subscriptionId = "<your subscription ID where the data factory resides>";
    string resourceGroup = "<your resource group where the data factory resides>";
    string region = "<the location of your resource group>";
    string purviewAccountName = 
        "<specify the name of purview account to create. It must be globally unique.>";
    
  3. 將下列程式碼新增至建立 PurviewManagementClient 類別實例的 Main 方法。 您可以使用此物件來建立 Microsoft Purview 帳戶。

    // Authenticate and create a purview management client
    var context = new AuthenticationContext("https://login.windows.net/" + tenantID);
    ClientCredential cc = new ClientCredential(applicationId, authenticationKey);
    AuthenticationResult result = context.AcquireTokenAsync(
    "https://management.azure.com/", cc).Result;
    ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
    var client = new PurviewManagementClient(cred)
    {
       SubscriptionId = subscriptionId           
    };
    

建立帳戶

將下列程式碼新增至 Main 方法,以建立 Microsoft Purview 帳戶

// Create a purview Account
Console.WriteLine("Creating Microsoft Purview Account " + purviewAccountName + "...");
Account account = new Account()
{
Location = region,
Identity = new Identity(type: "SystemAssigned"),
Sku = new AccountSku(name: "Standard", capacity: 4)
};            
try
{
  client.Accounts.CreateOrUpdate(resourceGroup, purviewAccountName, account);
  Console.WriteLine(client.Accounts.Get(resourceGroup, purviewAccountName).ProvisioningState);                
}
catch (ErrorResponseModelException purviewException)
{
Console.WriteLine(purviewException.StackTrace);
  }
  Console.WriteLine(
    SafeJsonConvert.SerializeObject(account, client.SerializationSettings));
  while (client.Accounts.Get(resourceGroup, purviewAccountName).ProvisioningState ==
         "PendingCreation")
  {
    System.Threading.Thread.Sleep(1000);
  }
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();

執行程式碼

建置並啟動應用程式,然後驗證執行。

主控台會列印建立 Microsoft Purview 帳戶的進度。

範例輸出

Creating Microsoft Purview Account testpurview...
Succeeded
{
  "sku": {
    "capacity": 4,
    "name": "Standard"
  },
  "identity": {
    "type": "SystemAssigned"
  },
  "location": "southcentralus"
}

Press any key to exit...

驗證輸出

移至 Azure 入口網站 中的 Microsoft Purview 帳戶頁面,並確認使用上述程式碼建立的帳戶。

刪除 Microsoft Purview 帳戶

若要以程式設計方式刪除 Microsoft Purview 帳戶,請將下列程式碼行新增至程式:

Console.WriteLine("Deleting the Microsoft Purview Account");
client.Accounts.Delete(resourceGroup, purviewAccountName);

檢查 Microsoft Purview 帳戶名稱是否可用

若要檢查 Purview 帳戶的可用性,請使用下列程式碼:

CheckNameAvailabilityRequest checkNameAvailabilityRequest = newCheckNameAvailabilityRequest()
{
    Name = purviewAccountName,
    Type =  "Microsoft.Purview/accounts"
};
Console.WriteLine("Check Microsoft Purview account name");
Console.WriteLine(client.Accounts.CheckNameAvailability(checkNameAvailabilityRequest).NameAvailable);

上述程式碼如果名稱可用,則列印「True」,如果名稱不可用,則列印「False」。

後續步驟

在本快速入門中,您已瞭解如何建立Microsoft Purview (先前稱為 Azure Purview) 帳戶、刪除帳戶,以及檢查名稱可用性。 您現在可以下載 .NET SDK,並瞭解您可以針對 Microsoft Purview 帳戶執行的其他資源提供者動作。

請遵循這些後續文章,瞭解如何流覽 Microsoft Purview 治理入口網站、建立集合,以及授與 Microsoft Purview 治理入口網站的存取權。