>> Hi my name's [inaudible] ,
and I work on the Azure Functions team in Microsoft,
and today I'm going to show you a new capability
we brought into Azure Functions,
and that's the ability to author PowerShell.
This gives you the ability to now perform
event-based automation across
your applications and your infrastructures.
So as you start to deploy your applications and you think about
all the different systems you have to
integrate in order to be able to manage that,
you now have the ability to author PowerShell in Azure Functions,
and integrate seamlessly across all these different systems.
So with that, let me go into a demo,
and I'll walk you through a scenario that you can perform
today to actually help you automate your entire application.
So in this demo,
I'm basically going to add a tag.
So I have a subscription,
and this is developer subscription,
so every time I get virtual machines created in there,
I want to add a tag to these so
that at night when they're not being used,
I want to automatically shut those down,
and so this saves a lot of cost,
and so it's something we'd want to be able to enforce
across all our developer and test subscriptions.
So with that, I'm going to switch over,
and show you that inside of the Azure Functions.
So here you can see we're in the Azure portal.
I'm going to walk you through how PowerShell now shows up as
a new language that's available inside of the experience.
So you can see here that we have now Azure Functions
for PowerShell, and of course,
we have all the great capabilities functions have to authoring
VS Code or in different editors or tools you're using,
as well as inside the portal.
We get all the rich templates
that are available so that you can trigger
this automation based on a whole set
of capabilities that Functions offers.
So in this scenario, I already had
three different functions created,
so one was every time
a new virtual machine gets created
or updated, I want to add a tag.
I have another one that says,
based on the tag information,
I want to start the machine.
I want to start in an hour, or I want to stop it.
So the nice thing about Azure Functions is you can
do all of your editing within the portal.
So here you can see I have PowerShell
now based on PowerShell 6 Core.
So this is using the latest PowerShell 6,
which is built on.NET Core.
So it can actually be developed on your Windows machine,
your Linux machine, or your Mac.
But inside the portal it doesn't matter,
so I can just author all the PowerShell that I normally would do,
and you can see here I've actually
done some integration with a Event Grid.
So one thing that's nice about Azure Functions is it
has this native integration into services in Azure.
So one of them I'm integrating with is Event Grid,
so let me show you what that looks like.
So if I go into my Event Grid's subscription,
you can see that every time a new machine gets created or updated,
I'm going to trigger
my function to actually go process that event.
If I look at the filters,
you can basically see that every time that I
have a virtual machine that was created or updated,
and there was a successful creation of that,
I want to get notified in my Azure Function,
and so this with Event Grid,
I can just set this up seamlessly in one or two clicks,
and now I can call my Azure Function.
So I go to my virtual machines,
and I click on my tags.
You can see I have a tag here
that I've added because I create this machine.
But if I deleted this and I saved it,
this would then go and Event Grid will pick up this change,
notify me, I have my function automatically run.
So I want talk a little bit about some of the benefits we've
added to bringing PowerShell into Azure Functions,
and how you can start to do that
yourself in your own organization.
So the nice thing is that you can do all of
these changes inside of the Azure Portal,
and integrate seamlessly into other services but you also have
a rich development environment in VS Code
where you could author all of your PowerShell as well.
So let me switch over to that and show you how you can do it.
Okay. So now if I go into VS Code,
there's a few things I want to show you that
we've done specifically to help
PowerShell work inside of the VS Code.
So the first thing I want to show is this profile.ps1 file.
So one of the advantages of using
Azure Functions as we have built-in managed identities,
and so that allows the function app to actually
authenticate itself and perform
actions across your entire subscription.
So because I've enabled managed identity on my function app,
I can now automatically authenticate my function
every time it runs using this profile.ps1.
So as the application starts up,
I'm going to authenticate myself and then
every single time a function runs,
I don't have to re-authenticate.
It will be done once across the life-cycle of
all the different functions that execute inside of the app,
but you could also add other capabilities into this profile.ps1,
that you want to have start up every time the application
starts before you actually execute functions.
Another critical thing we've added is
the ability to manage all of your dependencies.
So oftentimes when you're writing these functions in PowerShell,
you're going to want to integrate into other Azure services,
stop VMs, add tags, add certificates.
How you do that is typically with the Azure modules.
So how the Azure modules are enabled
inside of the service is, one,
you could install them
and upload them as part of your function app,
and so you can save those,
and put them in the modules folder and upload them,
but we've also added a new feature
that we've called Managed Dependency.
You can see there's a property here,
and we've enabled it to true.
So if you add this property now
on your PowerShell-based functions,
the service will actually identify this,
and it will look for requirements.psd1 file,
and so this now requirements.psd1 file is actually going
to get processed every time your function app starts up.
Because I've set it to "one dot star" this allows me to keep
up-to-date with the latest changes that have
happened inside of the ASI module.
So if the worst security fixes are
critical fixes that you wanted to get,
you can set this and the service would take care of
automatically updating those for you.
So that's the key benefit of not just having a modules available
but also keeping them up to
date so you don't have to worry about it,
and you focus mostly on just writing the business logic.
So again, if I go back in here,
one of the great things about
authoring in Functions is not that you can do in
the portal but you have the rich debugging
and authoring experience inside of VS Code.
So inside of here, if I wanted to debug this timer based one,
I could just add in wait-debugger,
and now what's going to happen is,
I'll be able to stop this function as it runs,
and then be able to attach a debugger.
So let me open up a prompt here,
so here I'm going to start the function app.
So you can see I'm starting it
locally and getting all of the Verbose logging,
so I can troubleshoot if anything's happening.
Now I'm going to call that function.
So this should be started,
and I should be able to actually attach to the debugger.
So I'm going to attach here,
and you can see I'm now inside the debugger, inside of PowerShell,
and I can step through debugger
just like I would if I was debugging
any other function except now we
can do it all locally inside of VS Code,
and this gives me the ability not only to identify
issues but I can change
variables inside of this experience as well.
So as I walk through here,
you can see I'm just stepping through,
found a virtual machine.
You can say I now have a cost tag.
So if I put out that cost tag,
you can see it's auto-shutdown is set to true,
start time 7:00 PM,
end time 7:00 AM,
but I could change one of those values because I'm
using PowerShell inside of
VS Code but because the functions experiences is
integrated I can actually go and change those,
and fully debug my experience locally here before I
publish it into the function service, and have it run there.
So this really gives you the ability to not only integrate
all your systems up in Azure but you can do it
locally as well inside a VS Code,
and take advantage of all work PowerShell offers.
Just to show how I completed,
if I go into my experience,
you can see what I've done is not only have I added a tag,
I've actually sent a notification into my team saying that
this machine I just
modified has been updated with that tag information,
If I click here,
what it does is it brings me back into
my portal experience so I can see that virtual machine,
and I should have actually added that tag that I deleted back in.
So now it will get shut down at 7:00 PM,
started up again at 7:00 AM automatically for me.
So I'll click into "Tags",
and you can see I added that costs tag
back with this auto-shutdown information.
So now my timers that I've just been
testing will kick in in the servers,
and automatically start and shut down
based on what the developer wanted for the virtual machine.
So let me end by going back into my PowerPoint
and show you some other scenarios that you can
perform as you start to operate,
access your application, and your
infrastructure using Azure Functions with PowerShell.
So here's some common event-based automation scenarios.
I showed you one about giving
you the ability to apply some rules on top of
your subscription so that you can recover some costs when
your resources are not being used but again,
you could integrate across
all different types of scenarios that you're doing
today but start to automate those
inside of Azure Functions using PowerShell,
and here's a few examples that we see a lot of
our customers doing as you could try out in your own organization.
So with that, I'm going to stop,
thank you for watching,
and I hope you get a chance to try out PowerShell,
it's in public preview right now inside of Azure Functions.