About the talk
Azure PowerShell function apps are a great option for all your Azure administration, event driven scripts and interaction with data in storage accounts or databases. But how do you use them? In this talk, We will take a look at the possibilities with some real-world examples as our guide. After that, let's see how you can get started with creating and deploying your own Azure Function Apps. With some practical demo's you will be ready to make the most of Azure Function Apps with PowerShell yourself.
Barbara works as the Azure technical lead for OGD in the Netherlands. She is a Microsoft MVP Azure, MCT and GitHub Star. Her focus is on Azure and automation in a very broad way. Think Serverless, Azure DevOps, PowerShell, GitHub and Infrastructure as Code. She loves teaching in an approachable way. She regularly writes posts for her blog https://4bes.nl and speaks at conferences and user groups. She helps grow the community as co-owner of the Dutch DevOps & GitHub community (DDOG), as well as co-hosting the Dutch PowerShell User Group (DUPSUG).View the profile
Welcome to the session when Powers combined Azure functions in Powershell talk a little bit about what other functions are, what flower show is what they can do when they are combined with each other and a bit on how you can work with them. My name is Barbara. Forbes. I am the answer, technical lead at otd in the Netherlands. I am a Microsoft MVP into a category and a GitHub star. You can follow me on Twitter. And this is at the NBA for Bes, which is also my handle. And if you want to read about Powershell
Azure functions in a lot of other, as your ultimation, you can find my blocked at force with a 4.9 l. Okay, when were talking after functions and file Rochelle first thing we need to think about is what is Powershell tool for automation? He's been around for a long time and I think everyone who has works with Windows Server Management in one way or another or whatever is probably familiar with Powershell cuz it has been the language for Windows development for quite some years and it started out with Powershell,
which is he, the logo over here. Just what's the latest version of Windows Powershell. But a few years ago. In Powershell team made the move to what then were school's Powershell core. And what is now just called Powershell show. This is it for now. So that's version, six or seven at the time of this talk, and barber shop has become open-source. A lot of development has been going on, has been going really fast and its multi-platform now so you can use them. The next you can use
AmEx as well as on the windows that you were already used to. So it's becoming love more power, Shiva powerful or she'll powerful and you can also use them combined with Azure functions. One, more person that I want to mention is far Show preview. You are able to use the preview version of Powershell and be the first to test new functionality in my experience to preview first is pretty stable. So it is usable with your daily work, but it is a preview version so you have no guarantees, but you do get the newest technology.
If you want to see everything that's behind Powershell, it's written in C. Sharp. If you want to see the code behind it. If you want to see the issues that they are working on or following you issue, or if you want to develop something yourself. You can find to get up purple story at the Link Bar, show Power show. Genesis Powershell know what are Azure functions? I think if you're in Astor filous conference, you might already be familiar with it. But let's just start with the basics. As a fraction is a part of the Surplus family is
so it's cheerful as confused and no that doesn't mean that there isn't a server there. It just means that you don't have to worry about that server. It's being done for you. So you don't have to worry about scaling. You don't have to worry about keeping track of some kind of a wish keeping it secure it, updated everything behind it. Gets taken away from you when you consider Powershell. It's basically like you might have had a scripting Surfer in some time. And there you would have scripts running
mouth. You can have two scripts running, but without the server, without worrying about it. But that's your functions as a little bit more because it's event-based, you can let it be triggered by an event and dead really help out when you're thinking about automation, especially, as your ultimation. So you can have, it be triggered by HP request, or by events happening in the portal, anything like that. Because look at the few examples in just seconds. You can use functions to manage boat as her, and a hybrid
environment, as a hybrid environment, does half a downside. And that is that the hybrid connection that you use cannot be installed on the domain controller. That's one of the main joint Surfer, if you have some salt on the surfer, so it's going to be pretty difficult to use it to manage, active directory, was for other use cases. You can use his in a hybrid environments without any issues. And you have a lot of smart things surrounding it, that makes it possible to run functions in parallel. So does can be a real time-saver, especially with functions that have a lot of
stuff to do and finally hear their native connection with other HR services. So, for example, you might be familiar. If your interaction with a storage account that you need to go grab the key from somewhere, make context make a connection with Azure functions can do that for you. They have triggers and bindings. You can have the storage account portable trigger to function with also use it as a binding so that you can store a file directly from your scripts in storage account. How does an Azure function work? This is a very
simplified overview of what an Azure functions us, or maybe not even that simplified. But basically, there is a trigger that can be input collected. There have been some magic in the middle and it creates an output. And the good thing you said that trigger that input and output you do not have to script that, there are default bindings Witten and Azure function to do this for you. Let's think of some examples of what a function can do for you. How would you use a function? And why I have an example
here to one that you might have used the most, because it's also available on automation accounts and It's easiest. It's Ricco manually is the HP to return and this means you could sort of an API, which you can call in the browser or true and invoke-restmethod. So you use an HP trigger to trigger the function to start the script. Script will start running and it will then return the information for you. And the example I have here is the function and it generates storage account name, so I might have to
explain that one, but I can show it in the portal. So here I have an Ender portal with me, just zoom in a little bit. And this is cool to find storage account name. And what this script does. Basically, it takes as her know, it takes an adjectives and a noun and combines them. And then see if that's torch account named already exists because the storage account name needs to be unique globally. And if it does not exist, give it back to you and say this is a correct service account name and the results are mostly funny. So, let's see what it will. Come up
now. So interesting here in the portal in my function and if I have function, so I can create more than one function to taste my needs. And here's that function gets the rich account name. And here I can just collect your URL and it's blocked here because I have a privacy Blocker on my window, but you will see it in the The Barbershop front in just a second because we're going to call this function and see if it works. So here I have Powershell brother. And I'll use invoke-restmethod
and then you were well to see if I saw a skunk named does at her websites. Net /? AP. I should, I just get storage account name. And this one is needed. So if I enter dish. It has found the source code name for me and the lights and blinds. Yeah. Anyway, it's create something for me that I can use create a storage account. I just saw this one pretty quickly and that's because I cheated a little bit because I have already trickers dysfunction, the second ago because that's something that's good to know in the free tier of
function has a startup time. It has to create a container with much else that you might have to find and has created all that stuff. So, that's might take a minute, maybe two depending on how much it needs to do, but it will stay active for about 10 minutes. So if you are 10 minutes in, It will be very pretty quickly. But after about 10 minutes of inactivity, it will delete the container again, and you get a bit of a longer. Of time is good to memorize, but in this case, I've done
it already. So it is pretty quick with giving satisfied reference. That's an interesting name. Let's just try one more fun. Eager. I took me some time either I sure will work anyway, so it's very simple. A silly example, simple example, but this is how you can use an HP trigger and just so it's it's a bit clearer here in the code. And test, you can find the script. This actually running and this is just a very basic Powershell script. And this is where it gets a response, so that there's a response and this is just it's creating and run them to him and checking if it's available.
So, that's one example, with HP trigger. Another example, one that might be very useful is the timer trigger where you can just sit that function to run at a specified time, which can be repeated without issues. And an example that I see a lot is have timer trigger to start virtual machines. You can have her phone. She needs to be stopped automatically from the virtual machine menu that's by default in their educational to start them automatically. You have to create some sort of automation for dads. And
there are is some of the nation available from the automation accounts, but that's really old scripts and a new one is coming up which is built on functions and logic apps. So there are some default options available. But before that was possible, I used to create a function with a timer trigger and for template 7 in the morning, I'll have to start all the first row machines. So that way I'll turn off between 7 + 7 and that means you don't have to pay for the on time for those 12 hours that you might confuse them anyway, and that our options, what you could do
you can have this Beast wigert's whenever a new file is added to a book storage. So a block of storage and is added to the storage account that will trigger the function to start running a script. And maybe for example, you want to keep an eye on that place or someone to be aware when something is added. So you can allow it to send you an email, through stand for it, which is a foot binding. So that's what you're going to have to be triggered by storage. Another option is to let it be triggered by a customer stated face. And in, for example, what
you can do is create some kind of come faithful with Jason and can be added to this Cosmos database and which Step count is Powhatan. Can can tree a ticket information and create the Starship count. So something like that can really help you. If you want to have some sort of shelter for option within a sure death for automating all dead. While still staying in the Powershell language. These are just a bunch of options that I've called, but there are so many options available here. You can see a lot of different options.
You can find it. In the documentation. There are a lot of bindings, a lot of triggers available, showing a lot of stuff to play with. Some other options and do want to mention. I mentioned storage already, but you can also make it went by to storage. So, with a message queue, you can really speed up your Automation and it triggered by a fence. You can have a trigger to buy Internet of Things helps and the whole separate category durable functions, which I will not go into in this store for shakes time. That's all very cool technology.
Not to mention for a second about the cost is a function rule. Run in a consumption plan and action plan is objectively cheap, really? You only pay for the time that the function is running. So unless your function is running 24/7, which is pretty impossible to do. It really doesn't cost that much and you can have you have to do a lot to get it late like five euros. For example, the graph you see here is a function that run very shortly, but it ran every day
for a month and the function itself cost to $0.01 the biggest car supposed to storage for the function. It was stored somewhere and actually the most expensive left a sure monitor. And mom has her rust because I kept track of the results of the function. So that was the most expensive thing. So this is very cheap to play around with. Now that's consumption plan and for a production use case, you might need to Premium plan or an app service plan with that you can have stuff like there's not a cold start show that for start-up is a lot
faster and you can run longer and you can run with private influence and I think there are more options available. But if you're starting out, especially if you're not running production, if you want to play around, this is with this. You do not absolutely do not need a Premium plan. You can run everything on a construction plans and play around without getting a giant bill at the end of the month. So let's take a quick look at how you can work with a function because I just mentioned that running functions is pretty cheap and ever but you do
need to have an address subscription if you don't have. But if you don't have that, you can actually still develop functions. You can run is all locally without having a subscription to have access to so that might help you out if you just trying to develop and understand the technology. I'm going to show you how you can do that. And I made a VM for this and dishes and actually a server 2022 because I could so hear. I have installed Visual Studio code. You do need to install some stuff, Visual Studio code and dumped me three.
One and the Azure function core tools. Powershell 7. There's a list, I think I got them all except the power show extension and Azure functions extension. So easy install those, then you can start running. So era. I have facial studio and here is the address where I can. So I'm going to click that. And here you can see. I have functions running and you see I'm not signed in to add her at this point. There's no connection with that her whatsoever. So we're going to create a new projects here in the first time. I take some time and there it is. I'm going to
use the current folder that I have open now. And of course he's going to ask me for a language. Well, that shouldn't be a surprise that work on a big fire shell of course. So here it is Powershell and it says I can select a template. So here are all the triggers that we just talked about and I'm going to use an HP trigger. And I can give that function a name will keep it simple. I'm going to use HP trigger one. No authorization level. This doesn't matter when you actually are running that function in a sure. If you have fun the numbness
function than everyone with access to do, you can use your can trigger your function and you just saw that with that storage account generator, that doesn't need any authorization at all. So, anyone can visit it with the storage account name. I don't really care if you want to do stats function and generate your own names and have a giggle about it. You go to school with me, but what if I have a function that actually does something within my exercise scription, then I don't want everyone in the world, to be able to exit is. So what I can do is use functional Precision
level and it will create a key added to the year around before it can be cold. So you can only covered with a key. There are other ways to make sure your function is she? Or you can use as your aide, a i d a d, but that's a bit out of here. That's going to be a hello will function. Show an ominous is fine, and we're not going to deploy to ask her anyway. And it's going to create a folder for me. Open some files. And here is a folder with all the files surrounding my
function would. This mean the most important one? This is just a Powershell script that you would write if you weren't running in a function, but you were running a local bar shell script. What I can do now is you think start. And it's below to Azure function core tools. And it's taking a bit of time, but here it's create a, you were all for me, a local house URL, which a stiffy trigger at the end. So let's just call me. Restaurant. And I don't open the Powershell window.
And now I should be able to make the slip them bigger. Do use info Christmas at like we just did. And Trigger does localhost. And once I click that, you should look in the window over here because there's more interesting stuff happening there. So if I press enter, it will start running here. Is he is being executed is creating a lock file that you can check. You can see what's actually happening here because see what's going on with your spritzers, very useful for local development says, it has run successfully, but there was no name face
it in. So let's create that. This isn't a real name. And I'll use my own name. And it now says hello and I can see over here to this has processed and it started. So this is great for all your local developments and first starting out and just trying stuff and seeing what happens. If you are ready with this, you are able to deploy directly to add her from here. If you connect a sure there will be at the 4 bus so you can actually deploy to ask her and see if it works there. If
you're doing this inappropriate auction and Vine with or with it seemed I would recommend using enter devilsaur get affections or some kind of CI CD progresh. Now, if you want to know more about Azure functions and Powershell, there are a few resources that I'd like to recommence first. I'm going to shamelessly pluck my own blog, because I've read a lot about extra functions with Michelle and I have step-by-step guides on how you can deploy to the portal, how you can deploy truassure Dental to get her actions
Basics on how functions work with queries storage, with Cosmos database, how durable functions work. So, I've got a lot of post all very much step-by-step Focus. So I would recommend if you want to try this out for yourself. Another option that are really lost overall is Mike, so learned and my shoulder and has a pulse on functions and a pulse on fire shell functions bus is not bar shelves based, but it is doable. So you can still Fallout 4 Longfellow to Powershell. And then make your own combination. If you're not
familiar with myself. Learn, this is a great resource. So I recommend it everyday, just try it out. And the last one that I want to mention is my get a proposed to her for 25 days of sure. Phyllis, me personally. I learn best. By example. I'd love to see what other people have risen, and make it my own, and for the 25 days of sure, Felicity supposed to challenge, 2019 to some time ago. We're in December, you had shirtless application to create everyday and I completed it completely with Josh Franks using Powershell,
some watch caps in there. But most of it is at her function of our shelter with a lot of different use cases, maybe challenges you can give yourself a reason to challenge is out there so you can see them there, and I answered all my coat there. There is one disclaimer. And I wrote that, these are bad examples of the reason for death is that these were 25 days that you had to do a challenge every day during December with the holidays, coming up, and I was working a full-time job. The side is so this was a hard work and that's some ugly code in there. So don't take
the code, is an example in bed really look at how. What is actually does. I did clean up some stuff. I think until 8:13, but the rest of them, it's pretty ugly. Cow. Yeah, it's functional. And I still think it might be nice. If not for my examples to do the challenges yourself because I really have to understand what's going on. So I think that's pretty much it. If you want to ask me any questions or want to know more, don't hesitate follow me and send me a message on Twitter and be 84 vs and would
Buy this talk
Buy this video
Our other topics
With ConferenceCast.tv, you get access to our library of the world's best conference talks.