Automatically initialize variables in Azure Functions

 

When working with Azure Functions and passing parameters in the HTTP request, this piece of Powershell comes in handy every time.

$Request.Query.GetEnumerator() | ForEach-Object { New-Variable -Name $_.Key -Value $_.Value }

This will make a variable from each parameter you pass in the request.
So for example;

If you request the following Azure functions URL:
https://darryl.azurewebsites.net/api/Get-Info?code=WrUum7c6ZM3YyyjY4O6Im8YtL7asx0ShxXJ5pUCDaL4832lsQYZkng==&myname=darryl

You will automatically have a parameter “myname” which you can use in your script.

 

Thank you for reading my blog.
If you have any questions or feedback, leave a comment or drop me an email.

Darryl van der Peijl
http://www.twitter.com/DarrylvdPeijl      

Leave a Reply

Your email address will not be published. Required fields are marked *