共用方式為


刪除 Azure DevTest Labs 中的實驗室或實驗室 VM

本文說明如何從實驗室刪除虛擬機器 (VM),或在 Azure DevTest Labs 中刪除實驗室。

從實驗室刪除 VM

當您在實驗室中建立 VM 時,DevTest Labs 會自動在個別的資源群組中建立 VM 的資源,例如磁碟、網路介面和公用 IP 位址。 刪除 VM 會刪除在建立 VM 時建立大部分的資源,包括 VM、網路介面和磁碟。 不過,刪除 VM 並不會刪除:

  • 您在 VM 的資源群組中手動建立的任何資源。
  • 實驗室資源群組中 VM 的金鑰保存庫。
  • VM 資源群組中的任何可用性設定組、負載平衡器或公用 IP 位址。 這些資源會由資源群組中的多部 VM 共用。

警告

刪除 VM 和實驗室是永久性的,而且無法復原。

若要從實驗室刪除 VM:

  1. 在 Azure 入口網站中實驗室的 [概觀] 頁面上,於 [我的虛擬機器] 下方的清單中尋找您想要刪除的 VM。

  2. 任一:

    • 選取 VM 清單旁邊的 [其他選項] (...),然後從捷徑功能表中選取 [刪除]Screenshot of Delete selected on the V M's context menu on the lab Overview page.

    • 選取清單中的 VM 名稱,然後在 VM 的 [概觀] 頁面上,從頂端功能表選取 [刪除]Screenshot of the Delete button on the V M Overview page.
  3. 在 [確定要刪除此項目?] 頁面上選取 [刪除]
    刪除 VM、其網路介面及其相關聯的 OS 磁碟是永久性的,而且無法復原。

    Screenshot of the V M deletion confirmation page.

  4. 若要檢查刪除狀態,請選取 Azure 功能表列上的 [通知] 圖示。

自動對實驗室中的所有 VM 進行刪除程序

身為實驗室擁有者,您可以在 Azure 入口網站中從實驗室刪除 VM。 您也可以使用 PowerShell 指令碼刪除實驗室中的所有 VM。 在下列範例中,修改 Values to change 註解底下的參數值。 您可以從 Azure 入口網站中的 [實驗室] 窗格擷取 subscriptionIdlabResourceGrouplabName 值。

   # Delete all the VMs in a lab.
          
   # Values to change:
   $subscriptionId = "<Enter Azure subscription ID here>"
   $labResourceGroup = "<Enter lab's resource group here>"
   $labName = "<Enter lab name here>"
          
   # Sign in to your Azure account.
   Connect-AzAccount
          
   # Select the Azure subscription that has the lab. This step is optional
   # if you have only one subscription.
   Select-AzSubscription -SubscriptionId $subscriptionId
          
   # Get the lab that has the VMs that you want to delete.
   $lab = Get-AzResource -ResourceId ('subscriptions/' + $subscriptionId + '/resourceGroups/' + $labResourceGroup + '/providers/Microsoft.DevTestLab/labs/' + $labName)
          
   # Get the VMs from that lab.
   $labVMs = Get-AzResource | Where-Object {
      $_.ResourceType -eq 'microsoft.devtestlab/labs/virtualmachines' -and
      $_.Name -like "$($lab.Name)/*"}
          
   # Delete the VMs.
   foreach($labVM in $labVMs)
      {
         Remove-AzResource -ResourceId $labVM.ResourceId -Force
      }          

刪除實驗室

當您從資源群組刪除實驗室時,DevTest Labs 會自動刪除:

  • 實驗室中的所有 VM。
  • 與這些 VM 相關聯的所有資源群組。
  • DevTest Labs 在實驗室建立期間自動建立的所有資源。

DevTest Labs 不會刪除實驗室的資源群組本身,也不會刪除您在實驗室的資源群組中手動建立的任何資源。

注意

如果您想要手動刪除實驗室的資源群組,則必須先刪除實驗室。 您無法刪除具有實驗室的資源群組。

若要刪除實驗室:

  1. 在 Azure 入口網站中實驗室的 [概觀] 頁面上,從頂端工具列選取 [刪除]

    Screenshot of the Delete button on the lab Overview page.

  2. 在 [確定要將其刪除?] 頁面上,於 [輸入實驗室名稱] 之下,輸入實驗室名稱,然後選取 [刪除]
    刪除實驗室及其所有資源是永久的,而且無法復原。

    Screenshot of the lab deletion confirmation page.

  3. 若要檢查刪除狀態,請選取 Azure 功能表列上的 [通知] 圖示。

    Screenshot of the Notifications icon on the Azure menu bar.

下一步