From f8b6ea87554f8268fa2cdcdb19c004a450ddcbe1 Mon Sep 17 00:00:00 2001 From: Nathan Windisch Date: Thu, 21 Nov 2024 14:52:30 +0000 Subject: [PATCH] Updated update-membership.ps1 to query the queue --- README.md | 2 +- groupmanager-v1-aa.template.json | 2 +- update-membership.ps1 | 25 ++++++++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ee00fd..ac9b4dd 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ _(via [PowerShell]() or a UNIX equivelant)_ 1. `git clone https://git.wnd.sh/neogroupmanager/az neogroupmanager` 2. `cd neogroupmanager` 3. `Connect-AzAccount` -4. `New-AzResouceGroup -ResourceGroupName groupmanager-p-v1-rg -Location ` +4. `New-AzResourceGroup -ResourceGroupName groupmanager-p-v1-rg -Location ` 5. `New-AzResourceGroupDeployment -ResourceGroupName groupmanager-p-v1-rg -TemplateFile ./groupmanager-v1.template.json -TemplateParameterFile ./groupmanager-v1.parameters.json` 6. `New-AzResourceGroupDeployment -ResourceGroupName groupmanager-p-v1-rg -TemplateFile ./groupmanager-v1-aa.template.json -TemplateParameterFile ./groupmanager-v1-aa.parameters.json` diff --git a/groupmanager-v1-aa.template.json b/groupmanager-v1-aa.template.json index 165ea21..0db610e 100644 --- a/groupmanager-v1-aa.template.json +++ b/groupmanager-v1-aa.template.json @@ -144,7 +144,7 @@ "description": "This runbook updates the membership of a group, by using the associated message queues to process requests.", "runbookType": "PowerShell", "publishContentLink": { - "uri": "https://git.wnd.sh/neogroupmanager/neogroupmanager/branch/main/update-membership.ps1", + "uri": "https://git.wnd.sh/neogroupmanager/az/raw/branch/main/update-membership.ps1", "version": "1.0.0" }, "logVerbose": false, diff --git a/update-membership.ps1 b/update-membership.ps1 index f0bd54c..5e4348d 100644 --- a/update-membership.ps1 +++ b/update-membership.ps1 @@ -1 +1,24 @@ -Write-Host "Hello, world!" # This is just a temporary test file! +$ManagedIdentityClientId = "612223b3-b7ae-4433-b09f-480e9aef2287" +$SubscriptionName = "core" +$ResourceGroupName = "groupmanager-t-rg" +$StorageAccountName = "wndshgroupmanagertv1sa" +$MaxMessages = 32 + +$null = Disable-AzContextAutosave -Scope Process +$null = Connect-AzAccount -Identity -AccountId $ManagedIdentityClientId -Subscription $SubscriptionName +$null = Set-AzCurrentStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName +# Get-AzStorageQueue complains (https://go.microsoft.com/fwlink?linkid=2258844), but it's the recommended method of getting messages... (https://learn.microsoft.com/azure/storage/queues/storage-powershell-how-to-use-queues#retrieve-a-queue) +$null = Update-AzConfig -DisplaySecretsWarning $false + +$StorageQueue = (Get-AzStorageQueue -Name "members").QueueClient +Write-Output "QueueClient.PeekMessages..." +$Queue = $StorageQueue.PeekMessages($MaxMessages) +Write-Output "QueueClient.PeekMessages!" +if (-NOT $Queue.HasValue -or $Queue.Value.Count -eq 0) { + Write-Output "No messages to process." + return +} +Write-Output "Queue.HasValue!" +Write-Output "Messages..." +$Messages = $Queue.Value.ForEach{[Convert]::FromBase64String($_.MessageText)}.ForEach{[Text.Encoding]::UTF8.GetString($_)} +Write-Output "Messages $(Measure-Object $Messages)!" \ No newline at end of file