>>Hey friends, we all know Azure Functions enables
you to run code on-demand without having to
explicitly provision or manage infrastructure, but get this. Now, you can use Azure
Functions to automate all your Cloud and On-premises
tasks using PowerShell. Amon O’Reilly is here to show me how, today on Azure Friday. [MUSIC]>>Hey folks, I’m Scott Hanselman, and it’s Azure Friday. I’m here with Amon O’Reilly to talk about one of my favorite things, Azure Functions, plus one of my
other favorite things, PowerShell.>>Awesome.>>It’s happening.>>It is. It’s all happening.>>Fantastic.>>Yes.>>This is PowerShell Core.>>Yep, PowerShell Core or
PowerShell 6 inside of functions. Basically, we’ve heard
a lot of customers using functions for all the event
based application development. We’ve also seen them, “Hey, how can I use this my event
place Cloud automation? So one of the primary languages
do that is PowerShell. So we said let’s add PowerShell
in the function so that now, they get all the benefits
of the functions, serverless, event based, but now
they use PowerShell to do it.>>This is PowerShell Core which is open source and powered by.NET Core.>>Correct. Powered by.NET Core, all open-source and we even use the latest easy modules
for Azure Management.>>Seriously. So this is
great. Now, when I want to write a whole website in this, or is it primarily for
administrative things?>>Generally, for
administrative things. That’s really what it’s good for
gluing, sticking things together, giving you those should
operationalize all of your applications and
infrastructure at the same time.>>Fantastic. Let’s see it.>>Yes, so inside the portal, you can see here that
I have a function. If I go to create a new one,
I’ll show you the experience. We’ve added PowerShell
as an option now. So you’ll be able to do all the same things
you could have if you set in other applications. So I can basically say, I’ll
do it inside the portal. I’ll just do a simple
Web Hook one for now. So generally, these we
used if you’re triggering them from some external
application that says, go ahead and provision a bunch of
my machines or add a database. So here, you can see now
it’s all Power literally in the browser based on
PowerShell 6 Core. I can go ahead and just run this
without making any changes. I get that same great experience. You can see down here
where it just runs. The output comes across
as, “Hello Azure”. So I can modify the input. I can do all my development testing
just like you would normally if I was developing locally
inside the browser as well, all running in PowerShell
based on PowerShell Core.>>Now, when probing
function into PowerShell, they expect to move fast. We think about what’s called
the developer’s inner loop.>>Yes.>>Make a change and check,
make a change and check it. Can you that with
PowerShell on Azure?>>Yes, that’s the real benefit, and we’ve actually done
a few extra features inside of functions to make it even easier to use PowerShell
than you normally would. A couple of
ways I could show you. So one of the first things
we’ve done is, we already had support for managed identity inside
of function apps. So this allows you
to get an identity. But if you grant that
identity access to your Azure resources like
your Azure subscription. Now, with PowerShell, we can
use that to go manage all of your systems from inside
the function app automatically. So we’ve made
a few changes so that it become very simple for you by basically using the identity built into PowerShell. I can
show you what that looks like.>>Let’s do it.>>Yes, so if I go into here,
and I look at the console, you can actually see that
there is a couple of extra files that we
have inside of an app. So the first thing I’ll
show you is that profile. So if I just type the profile.>>It’s so amazing that you’re inside of an Azure function and you’re now at a command line and you’re
looking at a profile that’s more.>>It’s pretty powerful.>>But it feels very PowerShell-y.>>Yes it does, and
you can basically do all the same stuff you would
normally do. So this is our Profile. So every time the
Function App starts up, we actually can run
this profile for you now. One the first things it does is, if you have Identity enabled, we will actually automatically
authenticate you. So you don’t have to do in
every single scripture write now.>>Because you’re
a customed PowerShell hosts.>>We are. So we have all this
ability built-in now.>>That’s so cool.>>So here’s another common task. You can actually add them into
this profile and they get run each time the function app starts up.>>That’s awesome. As
each time it runs, each time it starts up, how
is that scoping relationship?>>So basically, as you
know a function app basically is like a host, so it can have
multiple functions in there. So when the actual app
starts up, we will start it. Then, if you add more functions, they’ll inherit
identity automatically. It only does the
first time it starts.>>That’s nice.>>So something you can apply across all the functions you might be
writing for that function app, like identity is a common one, but there could be some of
the things you need to do. A couple of other things
I’ll show you that we’ve done to make it easier, if I type the host file, so we’ve added a new property called
“Managed dependency” in here. So what this is, it
allows you basically, to tell the function service that I want you to manage all of
my dependencies for me. The idea behind this
is, with serverless, we’re trying to basically abstract away all the complexity in managing infrastructure from the OS to the
runtime at the data at runtime. We’re now given ability to
also abstract away managing your modules and other dependencies
you have in third party, by automatically
updating those for you. So by setting this to true, what will happen when
the server starts up, it’s going to look in
this requirements file. So inside of here,
you can see, I set, “I want the AZ modules, and I want one.asterisk.” So basically, as
new AZ modules come out, I want the service take
care of integrating those in installing them
automatically for me. We’ll eventually get to that is every time there’s a security update
or critical update, typically you’re always in but stated my function app index
is am I compliance? Am I missing some security? Do I have to go and do
some analysis on it? You can restrict all that
away and say, “Service, you could take care of it, and
you automatically update for me.”>>So can I say, you said
one.star where that’s minor, can I go one.o.star and
they’re based on revision?>>Yes. So where in public preview, we’re limiting the one.star and then we’re going
to extend from there. So you get all the full flexibility
which would normally have.>>Because I wanted to
be serverless but I also don’t want it to break
if someone made a break.>>That’s right. So you can
fix it to a specific version or you can say “No I
trust certain vendors, and I just want to get those critical and security updates and install it.”>>That’s smart.>>So it just gives it that control
but also the flexibility, like I’ll do what I need to
do to make a service work.>>Fantastic.>>So these are just
built-in automatically, and you can take
advantage of them as you want you will just
turn them on and off, and then you can keep
adding from there.>>Well, you’re doing
a lot of this inside of the browser here, but sometimes, I hear people talking about
doing Azure functions on an airplane and they talk about how great the Azure
Functions runtime is. I assume I have flexibility?>>You have. So you can basically do all of this either
inside the browser or completely locally using VS Code and all of the local runtime
that we offer. So let me actually show you
a little bit of experience of that. But before I jump in there, I want to show you
a larger flow as well. It doesn’t really do
anything too special.>>You can close that one
there on the left right.>>Oh yes, it’ll open
up a little bit for me.>>There you go.>>Yes. So this is basically one
integrated with of anchorage. So what this does is, every time a database gets created, I want to get notification from
event created to call my function. Then, I’m going to with
that function see if it’s the last database in the SQL Server. If it is, I’m going to send
a notification to myself. So all of this done in with 20 lines of PowerShell which is
that glue you’re talking about. It’s so easy to connect
all these systems together. It took me about maybe 20 minutes
and I had the script running. I can basically, now, if I went in to add my databases. Let me just go to one here if
I can. Can you see, I credit,>>There is the SQL server there?>>Yes there’s a SQL Server
here in database. So I’ll just go in and delete it.>>Okay. If you got
a little SQL database here.>>I’m just going to delete this guy. So he’s called Friday
PowerShell and he’s gone. So now, because I cooked up
an Event Grid subscription to that, you can see here that every time now, that notification is going
to call my function. So this is the nice thing about
this event base automation model is that you can start to say, “Well, these events happen across Azure, and once I care about Call me, and then I’m going to process
those and do something on them.”>>Certainly, if someone deletes my database in production I’d like to hear more than just a
Teams notifications.>>That’s right you might
want some alarms to go off.>>We could even [inaudible]
that and fire that person.>>Exactly. So one thing you mentioned about
the local experience as well. So if I went into VS code, so the advantage we
have here is that, we have this function
extension that’s available already inside
of the Azure extension. So I can go in here and click on “Create” and I just
picked that Azure Friday. Seems PowerShell now is an option. So I can pick PowerShell
as my language. I can pick all the
different templates. So as there’s lots of
triggers available. All those triggers are available
for PowerShell as well, so I could say somebody drops
something in the queue. I want to go process
it with PowerShell, and that’s on a timer
trigger or using HTTP.>>So PowerShell is first-class?>>First-class across
the entire environment. So everything you
could do with C sharp, or Java, or Python, you could do now with
PowerShell as well. Very seamlessly, you
just pick whatever you want and it will go and
create that for you. So just like that, you’ll end up with just like you did in the Cloud, but now it’s all
local. Read about it. This is now you get all of the IntelliSense everything you’d want to do with PowerShell locally, plus you get local debugging, which is really what functions
gives you that power of it.>>Does that work on
Mac and Linux too? Because PowerShell
Core is [inaudible]>>It does. That’s a
real nice about it, because either your Mac reading here, you can have your Linux
environment running. It’ll work exactly the same way. Then you just debug, get it working, publish it in, and now you have all these automations just
running automatic in the Cloud.>>That’s amazing. Fantastic.>>Yup. So you can even see I just got an alert down here in Teams. So if I go into Teams, you can
see I just got a notification.>>Nice clean alert. It’s an alert that actually
is a little card [inaudible]>>It has. So you can see I
just leave Friday PowerShell. If I click in here, because I set up [inaudible]
that’ll bring me back into that SQL Server inside
my Azure environment I can see, was this the last database? What do I want to go
and do with this?>>Now, you got me thinking
about all the stuff I could potentially automate with
functions and PowerShell.>>It does. It really makes
it easy to glue these things together and start to automate
all your processes [inaudible].>>So we need to make sure
that all the PowerShell people out there that are running scripts, while true, need to know about this event-based way
of doing things [inaudible]>>It is. It’s like a new way
of thinking about doing work. Just like functions was,
but once you get into it, it really grows powerful and you
can start to build from there.>>Absolutely. This is a moving beyond cron jobs into something more>>That’s really what it is. It’s all about events now and how do I actually react
to those in real time.>>So this is in preview,
but coming soon, I can play with it now and I
can put it in production tune?>>That’s right. So
the next few months, it will go into general
availability and but we really like some feedback
during public preview, make sure it’s working well for you. It’s open source, so you can
get feedback directly on GitHub or you can ask
questions on our forums. I would love to get the feedback.>>Absolutely Brian. I am learning all
about Azure PowerShell inside Azure functions
today on Azure Friday. [MUSIC]

3 thoughts on “Serverless automation using PowerShell in Azure Functions | Azure Friday”

  1. I use Azure Runbooks that are triggered either by Flow or the web hook feature in Runbooks. What are the differences in between the two when it comes to powershell scripting? Do I have access to more features with Azure Functions? What are the cost differences between the two with the single purpose of using serverless powershell?

  2. I do not yet see Powershell as an option when running the azure functions extension within vscode, any update on when that will be made available for us?

Leave a Reply

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