Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,118 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a PowerShell function app that has a queue trigger that Invokes a run command on an Azure Vm. I'd like to write a message to a different queue same storage account from the function once the invoke command completes.
Is this possible to do? The goal is to send an email to the user who copied the file to let them know when the file is copied to the VM.
This is the code I'm running:
##################################################
# Web App writes to a 'fileUploaded' to queue
# this trigger when a file is copied to azure storage
##################################################
# Input bindings are passed in via param block.
param($QueueItem, $TriggerMetadata)
try
{
$FileName = $QueueItem['FileName']
$PDB = $QueueItem['PDB']
$EmailAddress = $QueueItem['EmailAddress']
$StorageAccount = 'https://STORAGEACCOUNT.blob.core.windows.net/CONTAINER/'
$BlobURI = "{0}{1}" -f $StorageAccount, $FileName
$ScriptPath = "F:\azCopy\CopyToDump.ps1"
# Append arguments directly to the script path for a positional argument passing
$ScriptFile = "$ScriptPath $PDB $FileName $BlobURI $EmailAddress"
# Create a the actual script-to-run as a new PS script
Out-File -InputObject $ScriptFile -FilePath .\ScriptToRun.ps1
Invoke-AzVMRunCommand `
-ResourceGroupName 'ciazuretst' `
-VMName 'oracle-win-vm' `
-CommandId 'RunPowerShellScript' `
-ScriptPath ScriptToRun.ps1
Remove-Item -Path ScriptToRun.ps1
##################################################
# TODO:
##################################################
# Would like to write to a 'fileCopied' queue
# when Invoke-AzVmRunCommand has completed
##################################################
} catch {
write-host "$_.Exception.Message"
}
Sorry - found the documentation for this - added the output binding to the function.json:
function.json:
{
"type": "queue",
"direction": "out",
"name": "Msg",
"queueName": "queuename",
"connection": "AzureWebJobsStorage"
}
Then just Push the message to the binding "name" Msg in run.ps1:
Push-OutputBinding -Name Msg -Value $message