As an IT professional, you’re already familiar with PowerShell for automation and Azure Functions for serverless computing. But did you know you can leverage these same skills to build powerful real-time applications? This post shows how to combine PowerShell Azure Functions with Event Grid and SignalR to create responsive, event-driven systems that notify users instantly when changes occur.
Traditional polling-based solutions are inefficient and create unnecessary load. Instead, we can build an elegant event-driven architecture that reacts instantly to changes:
Event Grid makes it easy to subscribe to storage account events. Here’s how to configure blob creation triggers:
// Event Grid subscription for PDF uploads
resource eventSubscription 'Microsoft.EventGrid/eventSubscriptions@2023-12-15-preview' = {
name: 'pdf-blob-subscription'
scope: storageAccount
properties: {
destination: {
endpointType: 'AzureFunction'
properties: {
resourceId: functionApp.id
maxEventsPerBatch: 1
}
}
filter: {
includedEventTypes: [
'Microsoft.Storage.BlobCreated'
]
subjectBeginsWith: '/blobServices/default/containers/pdfs/'
subjectEndsWith: '.pdf'
}
}
}
This configuration ensures your function only triggers for PDF files in the specified container, allowing you to process only the events you need.
Here’s where your PowerShell expertise shines. The function receives Event Grid events and processes them with PowerShell syntax:
function.json
) {
"bindings": [
{
"type": "eventGridTrigger",
"name": "eventGridEvent",
"direction": "in"
},
{
"type": "signalR",
"name": "signalRMessages",
"hubName": "pdfhub",
"direction": "out",
"connectionStringSetting": "AzureSignalRConnectionString"
}
]
}
run.ps1
) param($eventGridEvent, $TriggerMetadata)
# Extract blob information from Event Grid event
$blobUrl = $eventGridEvent.data.url
$fileName = Split-Path $blobUrl -Leaf
$containerName = ($blobUrl -split '/')[4]
Write-Host "Processing new PDF: $fileName in container: $containerName"
# Create SignalR message for real-time notification
$signalRMessage = @{
target = "newPdfUploaded"
arguments = @(
@{
fileName = $fileName
blobUrl = $blobUrl
containerName = $containerName
uploadTime = $eventGridEvent.eventTime
}
)
}
# Send to all connected clients
Push-OutputBinding -Name signalRMessages -Value $signalRMessage
SignalR Service handles the complex real-time communication infrastructure. Your PowerShell function simply pushes messages, and SignalR delivers them to all connected web clients instantly.
Push-OutputBinding
like any other Azure Function outputOn the client side, connecting to SignalR is straightforward:
const connection = new signalR.HubConnectionBuilder()
.withUrl("/api") // Your function app's SignalR endpoint
.build();
// Listen for new PDF notifications
connection.on("newPdfUploaded", (data) => {
console.log(`New PDF uploaded: ${data.fileName}`);
// Update UI in real-time
updatePdfList(data);
});
await connection.start();
Using Azure Verified Modules (AVM), you can deploy the entire infrastructure with a single command:
az deployment group create \
--resource-group rg-myapp-prod \
--template-file main.bicep \
--parameters workloadName="myapp" environmentName="prod"
This pattern works excellently for:
By combining Event Grid’s event detection, PowerShell Azure Functions’ familiar scripting environment, and SignalR’s real-time capabilities, you can build sophisticated real-time applications without leaving your PowerShell comfort zone. This serverless approach scales automatically, costs only what you use, and leverages the Azure skills you already have.