Azure PowerShell 簡介

已完成

Azure PowerShell 是模組的集合,用於直接從 PowerShell 管理 Azure 資源。 PowerShell 提供自動化功能,可讓您用來管理 Azure 資源。

Az PowerShell 模組是以 .NET Standard 為基礎。 它適用於所有作業系統上的 PowerShell 7.x 或更新版本。 它也與 Windows PowerShell 5.1 相容。

您可以在 Windows、Linux 和 macOS 的本機上安裝 Az PowerShell 模組。 您也可以透過 Azure Cloud Shell 在網頁瀏覽器中或在 Docker 容器內使用它。

必要條件

因為您的公司已經使用 Azure,您會有作用中的 Azure 訂用帳戶。 您在 Azure Cloud Shell 中使用 PowerShell。

建立資源群組

建立儲存體帳戶之前,您需要建立資源群組或使用現有的資源群組。

使用 New-AzResourceGroup Cmdlet 在 eastus 區域中建立名為 storageaccountexamplerg 的 Azure 資源群組:

New-AzResourceGroup -Name storageaccountexamplerg -Location eastus

建立儲存體帳戶

儲存體帳戶名稱長度必須是 3 到 24 個字元,且只包含數字和小寫字母。 儲存體帳戶名稱在 Azure 中必須是唯一的。

使用 Get-AzStorageAccountNameAvailability Cmdlet 來驗證您為儲存體帳戶選擇的名稱有效,且尚未使用中:

Get-AzStorageAccountNameAvailability -Name <storage-account-name>

使用 New-AzStorageAccount Cmdlet 來建立新的 Azure 儲存體帳戶。 必要參數為 NameResourceGroupNameLocationSkuNameKind 參數是選用的,且未指定時預設為 StorageV2

New-AzStorageAccount -Name <storage-account-name> -ResourceGroupName storageaccountexamplerg -Location eastus -SkuName Standard_RAGRS

驗證儲存體帳戶

您可以使用 Get-AzStorageAccount Cmdlet 來驗證儲存體群組是否存在。 沒有必要參數。 使用 ResourceGroupName 參數以只傳回特定資源群組中的儲存體帳戶。 使用 NameResourceGroupName 參數以只傳回特定儲存體帳戶。

Get-AzStorageAccount -Name <storage-account-name> -ResourceGroupName storageaccountexamplerg

清除資源

使用 Remove-AzResourceGroup Cmdlet 以刪除資源群組。 唯一的必要參數是 Name。 刪除資源群組會刪除群組及其包含的所有資源。 如果您在此單元中建立的儲存體帳戶範圍以外的資源存在於 storageaccountexamplerg 資源群組,則其也會遭到刪除。

Remove-AzResourceGroup -Name storageaccountexamplerg

使用 Remove-AzStorageAccount Cmdlet 來移除儲存體帳戶。 必要參數為 NameResourceGroupName

Remove-AzStorageAccount -Name <storage-account-name> -ResourceGroupName storageaccountexamplerg