簡體   English   中英

如何通過Azure DevOps從Azure刪除存儲帳戶

[英]How to remove a storage account from Azure through Azure DevOps

在Azure PowerShell任務中運行Remove-AzureRmStorageAccount命令時,出現此錯誤:

2019-01-24T13:07:29.0148404Z ==============================================================================
2019-01-24T13:07:29.0148533Z Task         : Azure PowerShell
2019-01-24T13:07:29.0148602Z Description  : Run a PowerShell script within an Azure environment
2019-01-24T13:07:29.0148688Z Version      : 3.1.18
2019-01-24T13:07:29.0148847Z Author       : Microsoft Corporation
2019-01-24T13:07:29.0148947Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
2019-01-24T13:07:29.0149050Z ==============================================================================
2019-01-24T13:07:30.2233628Z ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM\6.13.1\AzureRM.psd1 -Global
2019-01-24T13:07:42.1447157Z ##[command]Clear-AzureRmContext -Scope Process
2019-01-24T13:07:42.7204663Z ##[command]Disable-AzureRmContextAutosave -ErrorAction SilentlyContinue
2019-01-24T13:07:43.0466903Z ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2019-01-24T13:07:44.1568578Z ##[command] Select-AzureRMSubscription -SubscriptionId XXXXX -TenantId ***
2019-01-24T13:07:44.5546953Z ##[command]& 'D:\a\_temp\XXXXX.ps1' 
2019-01-24T13:07:44.6950579Z ##[command]Disconnect-AzureRmAccount -Scope Process
2019-01-24T13:07:45.1149833Z ##[command]Clear-AzureRmContext -Scope Process
2019-01-24T13:07:45.5569262Z ##[error]Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.

在Azure環境中運行PowerShell腳本

這是我運行的腳本:

Remove-AzureRmStorageAccount `
    -ResourceGroupName "myResourceGroupName" `
    -AccountName "mystorageaccountname"
    -Force

請注意,我可以用相同的方式創建存儲帳戶和blob容器,而不會出錯。 該腳本可以正常工作:

if(Get-AzureRmStorageAccountNameAvailability -Name "mystorageaccountname")
{
  New-AzureRmStorageAccount `
    -ResourceGroupName "myResourceGroupName" `
    -AccountName "mystorageaccountname" `
    -Location "West Europe" `
    -SkuName "Standard_LRS"

  New-AzureRmStorageContainer `
    -ResourceGroupName "myResourceGroupName" `
    -AccountName "mystorageaccountname" `
    -ContainerName "my-blob-container" `
    -PublicAccess "Blob"
}

如何通過Azure DevOps管道使刪除正常運行而沒有錯誤?

發生這種情況是因為其要求確認刪除( ##[error]Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available ),您丟失了:`。

Remove-AzureRmStorageAccount `
    -ResourceGroupName "myResourceGroupName" `
    -AccountName "mystorageaccountname" ` <<<<< here
    -Force

剛剛重新測試過,如果您提供-Force ,它將在沒有提示的情況下工作

暫無
暫無

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

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