we've got another wvd video for you at the azure academy and today we want to
answer the question of how we can save money on wvd and put the ability for our
users to power on and off their vms without having to bother i.t
so join us for the next few minutes as we create a windows virtual desktop
power management system
i'm Dean Cefola and this is The Azure Academy if you want to master the Azure
cloud you can start right now by clicking the subscribe button and the
notification bell so you don't miss anything
so here in the wvd admin portal i've got a personal host pool and that's set up
currently with one virtual machine and if our user who owns this tries to
log in they're going to have a problem and that
problem is that this vm is currently unavailable now why would that be so if
we click on rvm we can see that the current status
of this vm is that it is stopped so i either have
to wait for the scaling tool schedule to turn on my vm for me or i've
got to ask somebody in it can you power on my vm because it's
currently off now if it isn't available it's in the middle of the night or
you've got some executive who wants to log onto their system this is obviously
a problem now today there's a bunch of ways of
course that you could handle this you could give people access to the azure
portal which isn't always recommended you can put in a support ticket which
can take a while or we can do what i'm going to show you
today so here's my mobile phone and if i open up one of my folders where i've got
my wvd client that's the one on the right i've
also got another one here for wvd power on so if i open that
app see what we're loading here is a microsoft power app
and we're signed in and boy look at that what i can do
is just power on my vm so i'll click power on
and when i do the vm is starting up by creating a
power app i was able to give this ability right to one of the users
who owns this particular vm so now they can turn it on
and off whenever they want so now that our vm's up and running we can just log
in i'll go back to my mobile phone and open
the rd client and when i do i don't have anything set
up here so i've got to register for this first by adding a workspace and now i
can type in my email or i can provide a url and when
i type in my email address i've got another problem which is that
no workspaces are found now i know that that's not
true i do have a workspace because i've used wbd a lot of times so this is the
second problem that we'll address in a few minutes
so a few days ago on twitter i saw this post from tom hickling who is one of the
microsoft wbd global black belts and this caught my attention because of this
very scenario and so i clicked on the link here
to aka dot ms slash wvd auto that brings you over to tom's blog where
he gives you all of the directions for how to do this and
this is the process that we're gonna walk through today so step number one
we need to go to flow.microsoft.com and then you just sign in with your
regular credentials and then over on the left we'll go to
my flows and you can see i've already got two flows here one for power on one
for power off and that's the first thing that we need to
create and we do that by going to new instant from blank then we have to give
our flow a name i'll call my wbd power on and we'll
select a power app as our trigger and hit create so we're going to click here
to add a new step and then we're going to type in
http and then i chose http premium here then we have our method and
then we're going to select post which means that we're going to use the arm
apis here so we need to go to another doc
and inside all of the azure docs you can find these references that'll give you
the api and powershell and other kind of
commands at the bottom here we have the start api which i'll click on
that and then we can just copy this code and i'll just paste that into a notepad
here just to make it easy we need to change some of the text here to add our
subscription id resource group name and then the name of
the virtual machine that we want to start
and there we go and i'll copy all of that code and go back to our flow and
put that here in the uri now we need to connect it to azure and
we can do this in the advanced options and we'll select the
authentication here by active directory oauth back in the azure
portal we'll need to grab our azure active directory
tenant id which we can find by going to azure active directory and then clicking
to copy the tenant id and back in the flow we'll put that in
the tenant box for our audience and this is where we're
directing the api call and that's going to be to
management.azure.com and now we need to set up a client
id now in azure active directory terms this is an
application and it's this application that we're going to grant the
permissions to be able to do the start and stop
and under app registrations i've already got one here called
test power app and i'll create a new one for you and i'll call it the wbd power
trigger and this is only going to work with a single tenant so i can leave this
middle section alone and then for the redirect uri so i'll
just put in here ms azureacademy.com slash wbd
wvdpowertrigger and no this does not need to be a valid
url in case you were wondering and i'll click the register button and
that has now created an azure 80 application and we want to
copy here the application or client id and we'll put
that in our flow and now we need to generate a secret so
we'll go back to azure id on the left go to certificates and
secrets and at the bottom create a new client secret
and i'll just call this the wbd power trigger secret and then you can set
how long it will be before this secret expires one year two years or
never in this case i'll just set one year and click add so very important
here we do need to copy this secret because once we click out of
this screen then this secret is going to be locked and we won't be able to get
back to it so copy that into your notepad and now
we need to assign permissions so i'm going to go to my
resource group where my target vms are located
which is msaa wbd and i'll go to access control
and i'll set a role assignment and i'll make this a
virtual machine contributor and i'll search for my wbd power
trigger and then hit save and if we scroll down there we've got our virtual
machine contributor rights so i've got that copied and we'll paste
that right here into our flow and then we'll click the save button and
that step is complete now you can additionally set up a notification
trigger that this whole process completed successfully
so you could set up mobile notifications you could set up a post to microsoft
teams or just a general email so any way that
you like to do it and since i'm setting this up for the
user nova because this is his personal vm i'll put his email address in here
and i'll give it a subject of wvd power on complete and the body
says your wvd vm power on has completed and
you can sign in i'll hit save for that now over in the top right we have the
flow checker which will just verify that you have no errors or warnings in your
process and then i'll hit save and you can test
this flow right from here before we go on to the
next step of creating the power app but i'm actually going to go back
because we want to set up another new flow
and this will be for the power off so we'll go back and set a new
instant from blank again we'll call this flow wbd power off
set our powerapp trigger and hit create and then we'll follow the same steps in
the process we'll add a new step this will be http and i'll choose the
http premium here for our method it'll again be a
post and for our uri we'll go back to the azure documentation
and this one we want to be the dealocate api
which i'll copy over to my notepad and i'll make the updates to call my
specific vm and i'm just plugging in the same
information my subscription id the resource group name and then the
name of the virtual machine itself you can
see this api is going to be calling the deallocate
command so we'll copy all of that back to our flow and then
we'll choose the advanced options using active directory oauth for our
authentication back in azure active directory we'll grab our tenant id and
paste that into our flow and then under our app registrations
we'll copy our application client id into the flow as well and
finally we'll place our secret here so we've got the exact same
setup as before just calling the deallocate api
and we'll save that and we'll add another new step
for an email notification and i've set my subject and body
to tell nova that his vm has powered off and we'll hit save
we'll do our flow checker and everything looks good
so we'll hit save so a very easy process to set up
our power on and power off triggers and let's do a test here since our vm is
currently powered on we'll run the power off trigger and
click run flow and then we can click here to
watch the run and our flow is currently running
so let's go and check on our virtual machine and our vm status is currently
updating and if we hit refresh we are now deallocating now we move on to
creating the application that the user is going to
interact with and this is going to be at powerapps.microsoft.com
and i've got my app that i've already created and i'll create a new one for
you so you can see the whole process so we'll go on the left here to create
and we'll create an app from a blank canvas and i'll call
this the wbd power trigger and i'll be selecting this for a phone
and hit create so at the top we'll go to insert and
i'll insert a button here and position them wherever i like and
i'll rename the text over here on the right to wbd power on
and then a little further down we'll click to change the color of the button
and i'll make this a green and then we'll go to click on our other button
and rename this one we'll call this wbd power off and we'll
set the color for this one to be red now you can make this look however you
like and add whatever additional text you want
or we can add some graphics and then go over here on the left
to the media button and i'll click to upload some graphics
and i'll add the wbd logo and then i'll go back and add another one
and i'll add my new azure academy logo then we just have to drag them into
place so at the top now i'll click on actions
and we want to add the power automate function which is going to join
our flows here so we want to add this to our power on button
and then we want to add our wvd power on and once that's complete we just need to
close our parentheses at the top and then you can see that the power on
run a trigger will equal true and we'll just hit enter for that
and our power on is complete so now let's do the power
off we'll click power automate select our power off flow we'll add the
closing parentheses and hit enter and we are done so at this
point we need to save this so i'll go to file and click save as and
we want to be sure that we're saving this to the cloud and not to our local
computer we'll leave the name as wbd power
trigger and in the bottom right corner we'll hit save and
our power app is now saved now we can share this right over
to nova now nova is not going to need to make
any edits here so we don't have to check the co-owner button
we'll just click share and that is on its way to nova so if you had
five users you'd have to map the same process
for the five different users to the five different vms and then share them with
the users appropriately back in the azure portal
now i've got my iphone up here again we'll go into the
app store and we'll search for microsoft power
apps and then we'll download and install that
and now that that's downloaded we'll go ahead and launch that and
sign in with our nova credentials and you log on here to the my
apps screen and of course nova has not created his own
power app so we need to go at the top to all
apps and then we can see the wbd power trigger
so we'll click on that and now we need to sign in and grant permission here
and at the bottom we'll hit the accept and connect
and we are now signed in so we'll click the allow button
there is our application and as you can see over in the background
our vm is currently in a stopped state so we'll click the power on trigger
and our vm is starting up so i'd like you to tell me in the comments what you
think of the new banner that we have for our youtube
channel and if you have any suggestions for new videos give me
those in the comments down below now let's slide out to go back and now
we want to add this to our home screen so we don't have to
open powerapp and sign in we want all this to kind of
happen for us so we'll click the three dots and then click
pin to home and then on an iphone we'll click to open the share tray
and then we scroll down just a little bit and tap on the add to home screen
and then we just click add now i've added that and of course i can just tap
on it again to get right back to where i was
it'll launch the power app in the background load my power trigger app and
i'm ready to power on or off my virtual machine
now i did say we had a second problem to solve today and that was that our rd
client were not signed in and we go to add a new workspace
and type in our email and when we do it says that there are no workspaces found
we could put in the url but it's not something that people are
likely to know or remember on their own we want to make this setup as easy as
possible so to do this we need to add some stuff
to our dns i've got a link for this right in the
video description now over in the azure portal is where i have my public dns
zone and i'll go and add a new record and
this record will be called underscore msradc and the
type will be a text record we'll leave the time to live at 1
hour which is also 3 600 seconds and we'll add our value
of our feed discovery url and we'll hit ok
and you can see our record has been added now if you're like most
organizations you would have an internal and external dns like mine are then you
should add the feed discovery to both places and
here's the dns on my domain controller i'll right click on my zone
and go to add an other new record we'll scroll down
and add a text record and we'll add the exact same thing
underscore msradc and then we'll add our feed discovery as our text back on
my iphone if i add my email address now the dns has been updated
and it searches and now it finds my feed so i can launch my personal desktop here
give it my credentials and then click continue
so let me go through the process for the end of the day now
i'm finished doing all of my work i'll just click on start
go to do my sign out process and then i'll go back to
my power app then we'll click our wwd power off button
and we can see in the background that our vm is deallocating
so hope this video has been helpful for you to give your users
back some of the control take some of the pressure off of it
and help you save some money in the process so if you learned something new
today go ahead and click the thumbs up as well as subscribe to the azure
academy if you haven't done that yet and we just want to help you to master
all of azure so if there's something that we haven't
covered in a video please give me some comments so we can add
those videos for you to help you out and if you want to keep on learning over on
the top right we've got our latest video as well
as another one on the bottom that we picked out
just for you so that you can keep growing in your azure skills
thanks again for joining us this week and we will see you next week at the
same time happy learning