Updated update-membership.ps1 to query the queue

This commit is contained in:
Nathan Windisch 2024-11-21 14:52:30 +00:00
parent 2728e07ff0
commit f8b6ea8755
3 changed files with 26 additions and 3 deletions

View File

@ -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 <uksouth>`
4. `New-AzResourceGroup -ResourceGroupName groupmanager-p-v1-rg -Location <uksouth>`
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`

View File

@ -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,

View File

@ -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)!"