Samples/Example 01.ps1
<########################################################
Author: Trevor Sullivan <trevor@trevorsullivan.net> Website: https://trevorsullivan.net Twitter: https://twitter.com/pgeek86 ########################################################> #region Setup ### Import the PSAzureQueue module # Import-Module -Name "C:\Users\TrevorSullivan\Documents\visual studio 2015\Projects\ClassLibrary1\bin\Debug\PSAzureQueue.dll"; ### Install the module from the PowerShell Gallery Install-Module -Name PSAzureQueue -Scope CurrentUser; ### Inspect commands in the module; Get-Command -Module PSAzureQueue; #endregion #region Storage Account and Queue ### Authenticate to Microsoft Azure $AzureUsername = 'trevor@trevorsullivan.net'; $AzureCredential = Get-Credential -Message 'Please enter your Microsoft Azure password.' -UserName $AzureUsername; $null = Login-AzureRmAccount -Credential $AzureCredential; ### Specify the Storage Account that the Azure Storage Queue will be created in $StorageAccount = @{ ResourceGroupName = 'trevor'; Name = 'trevorsullivan'; }; $StorageKey = Get-AzureRmStorageAccountKey @StorageAccount; ### Create Storage Context (authentication for Azure Storage service) $StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccount.Name -StorageAccountKey $StorageKey.Key1; ### Create an Azure Storage Queue in the Azure Storage Account $StorageQueue = @{ Context = $StorageContext; Name = 'orchardtoys'; }; if (!(Get-AzureStorageQueue @StorageQueue)) { New-AzureStorageQueue @StorageQueue; } #endregion #region Get information about an Azure Storage Queue $Queue = @{ StorageAccountName = $StorageAccount.Name; StorageAccountKey = $StorageKey.Key1; Name = $StorageQueue.Name; Verbose = $true; } Get-AzureStorageQueueInfo @Queue; #endregion #region Add some messages to the queue if ((Read-Host -Prompt 'Add messages?') -eq 'y') { $QueueMessage = @{ StorageAccountName = $StorageAccount.Name; StorageAccountKey = $StorageKey.Key1; Name = $StorageQueue.Name; Content = ''; } foreach ($Process in (Get-Process)) { $QueueMessage.Content = $Process | ConvertTo-Json -Depth 1; New-AzureStorageQueueMessage @QueueMessage -Verbose; } } #endregion #region Read messages off of the queue if ((Read-Host -Prompt 'Get message?') -eq 'y') { $Queue = @{ StorageAccountName = $StorageAccount.Name; StorageAccountKey = $StorageKey.Key1; Name = $StorageQueue.Name; Verbose = $true; } Get-AzureStorageQueueMessage @Queue } #endregion #region Remove message from queue if ((Read-Host -Prompt 'Get message?') -eq 'y') { $Queue = @{ StorageAccountName = $StorageAccount.Name; StorageAccountKey = $StorageKey.Key1; Name = $StorageQueue.Name; Verbose = $true; } Get-AzureStorageQueueMessage @Queue | Remove-AzureStorageQueueMessage @Queue; } #endregion |