Я использую Azure PowerShell для создания и добавления записей в очередь Azure, следующий пример здесь: MSDN: Использование Azure PowerShell с хранилищем Azure - Как управлять очередями Azure.
Вот мой сценарий PowerShell:
$storeAuthContext = New-AzureStorageContext -StorageAccountName '[my storage account name]' -StorageAccountKey '[my storage account key'
$myQueue = New-AzureStorageQueue –Name 'myqueue' -Context $storeAuthContext
$queueMessage = New-Object -TypeName Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage -ArgumentList 'Hello'
$myQueue.CloudQueue.AddMessage($queueMessage)
Это отлично работает при первом запуске.
Второй раз получаю вот что:
New-AzureStorageQueue: очередь myqueue уже существует. В строке: 1 символ: 12 + $ myQueue = New-AzureStorageQueue –Name 'myqueue' -Context $ storeAuthContext + ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: ResourceExists: (:) [New-AzureStorageQueue ], ResourceAlreadyExistException + FullyQualifiedErrorId: ResourceAlreadyExistException, Microsoft.WindowsAzure.Commands.Storage.Queue.NewAzureStorageQueueCommand
В .NET Azure Storage API есть cloudqueue.createifnotexists (MSDN), но я не могу найти аналог в Azure PowerShell.
Как лучше всего в PowerShell создать очередь хранилища Azure, если она еще не существует, иначе получить ссылку на существующую очередь?