客户须要定时发送信息到Azure Storage Queue,因此尝试使用Azure Runbook实现这个需求。shell
首先新增一个Azure Automation Account的资源。测试
由于要使用Az.storage模组发送消息到Queue, 可是这个模组并无包含在默认模组中,因此要手动添加一下。选择 Shared resources 下面的 Modules gallery.spa
由于Az.Storage依赖Az.Accounts模组,因此咱们先搜索Az.Accounts, 找到后,双击打开新窗口,点击Import。导入大概须要几分钟,导入成功后,咱们重复一样的步骤添加Az.Storage模组。3d
都添加成功后,咱们就能够添加咱们的Runbook了code
从左边的菜单栏选择Runbooks,而后Create a runbook, 输入名字,选择类型Powershellblog
具体的powershell脚本以下ip
$connectionName = "AzureRunAsConnection" $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName Write-Output($servicePrincipalConnection.TenantId)
Connect-AzAccount ` -ServicePrincipal ` -Tenant $servicePrincipalConnection.TenantId ` -ApplicationId $servicePrincipalConnection.ApplicationId ` -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint $storageAccount=Get-AzStorageAccount -ResourceGroupName "******" -StorageAccountName "********" #这里输入你本身的resource group名字和storage account的名字。 $ctx=$storageAccount.Context $queue=Get-AzStorageQueue -Name "test-spfx" -Context $ctx $queueMessage = [Microsoft.Azure.Storage.Queue.CloudQueueMessage]::new("This is message from runbook") $queue.CloudQueue.AddMessageAsync($QueueMessage) Write-Output ("Send message to queue.")
这里的AzureRunAsConnection是使用的资源组默认样例的参数,能够根据本身的实际须要修改或添加。具体位置是在Shared Resources下面的Connectionsci
最后能够测试runbook,去storage account下面检查,是否成功接收到消息。资源