Slides from M365 Twin Cities 2023

A huge thank you to the attendees, organizers, volunteers, sponsors, and anyone else involved with M365 Twin Cities. This was my first community conference in 3+ years but it was amazing to share more about Microsoft Graph in my two sessions. I appreciate all of the attendees who joined and had great questions and engagement.

Below are PDF copies of the slides I presented. If you have any questions, feel free to ask in the comments here or reach out to me. Look forward to presenting at more events later this year as opportunities arise.

Getting Up to Speed with Microsoft Graph Development

How to Use Power Automate and Microsoft Graph in Daily Work

-Frog Out

Resources (see more in Resources on this blog)

Microsoft Graph developer center
https://aka.ms/Graph

Microsoft Graph Explorer
https://aka.ms/ge

Microsoft Graph Postman collection
https://aka.ms/GraphPostman

Microsoft Graph extension for Polyglot Notebooks
https://github.com/microsoftgraph/msgraph-dotnet-interactive-extension

Microsoft 365 platform community call (series invite)
https://aka.ms/m365-dev-call

Presenting at M365 Twin Cities 2023

After a few years off from community speaking engagements I’m excited to return to speak at M365 Twin Cities (formerly SharePoint Saturday Twin Cities, now with expanded scope and topics) on Jan 21, 2023. I’ve spoken at this conference twice before and have been very impressed with the level of organization, attendee engagement, and content all-up. I’ll be presenting the following 2 sessions. Registration is still open. If you are in the area, please sign up and look forward to seeing you there.

M365 Twin Cities
https://www.m365tc.com/

Registration
https://www.eventbrite.com/e/m365-twin-cities-winter-2023-tickets-471566266397

Title: Getting Up to Speed with Microsoft Graph Development

Description: “I hear that I need to use Microsoft Graph for developing against Microsoft 365 but I have no clue where to start.” “I want to grant access to company data without throwing in the entire kitchen sink.” Fear not fellow developers and admins. This session we will ramp you up to a 200 level knowledge on the pertinent parts of Microsoft Graph including endpoints available, syntax, authentication flows, and more. We will also cover useful examples of what can be accomplished using these APIs. Prior experience with Microsoft Graph is not required but can be helpful.

Title: How to Use Power Automate and Microsoft Graph in Daily Work

Description: Do you need to automate parts of your daily work routine? What Microsoft Cloud data is available through Microsoft Graph for automating? In this session we’ll walk through multiple real world examples of using Power Automate for daily tasks such as assigning round robin tasks to team members, sending weekly reminders, processing survey results, and more. Prior experience with Power Automate is useful but not required. Target audience is open to all (productivity workers, developers, admins, etc.)

-Frog Out

Power Automate Sample – Custom Microsoft Teams Reminder for Meeting

In this post I’ll walk through a sample workflow I created for sending out Microsoft Teams messages for a team sync meeting. This is part of my Spring 2022 Fix Hack Learn (FHL) project.

Requirements

  • Send individual reminder to teammates (35+) to capture “weekly accomplishments” for next sync meeting
  • Schedule to run weekly (Fridays)

Solution

The high-level architecture for the solution I prototyped is as follows:

  • Trigger
    • Recurrence – weekly on Fridays
  • Actions
    • Create variables for tracking date when flow is run and “next Tuesday”
    • Create copy of template file and rename to desired filename
    • Get list of team members
    • For each team member
      • Send Teams message with link to above file

Below is a sample of the Teams message that is sent.

Challenges

Dynamic links in Teams chat message

When using the HTML designer for the Teams “message”, you are only able to specify static links. In our scenario we need to include a dynamic link to the upcoming document for weekly accomplishments.

Through some investigation online (link) we found that this can be achieved using the Code View. Once in Code View, you can specify an HTML anchor element <a href=…> and include the “link to item” for the file in SharePoint.

Rename files in SharePoint Online document library

Power Automate has a SharePoint action for copying a file, but you have little control over naming the file (ex. replace, new copy with an incremented integer, etc.). Separately, there are currently no native actions for renaming a file.

Instead, I found a quick workaround (link) to copy the contents of an existing “template” file and then create a copy using the contents of the template file. In the process we can provide whichever name we desire.

Calculate date for “next Tuesday”

As part of the renaming of file, I wanted this flow to be able to dynamically calculate the date for the next Tuesday on the calendar. Aside from being an interesting calculation I was personally curious about, this would also allow sending out the reminder on any day of the week.

After much searching online, I found solutions for calculating this in Excel (example), but that made use of a different set of functions that are not available in Power Automate. In the end I decided not to spend too much time on this and instead hard coded the calculation to be Friday’s date + 4 days. See below for the formula.

formatDateTime(addDays(variables('currentDate'),4), 'yyyy-MM-dd')

Conclusion

Hopefully this example can give you inspiration if you need a similar solution for sending out customized reminders of a recurring event or meeting. I was surprised at how quickly I was able to prototype the first iteration of this (less than 1 hour) and then iterate on it with a few enhancements before the day was done. I’m a big fan of how easy Power Automate makes it to automate and simplify manual processes. If you have any suggested improvements, share them in the comments.

-Frog Out

Resources

Flow does not generate clickable links for dynamic paths
https://powerusers.microsoft.com/t5/General-Power-Automate/Flow-does-not-generate-clickable-links-for-dynamic-paths/m-p/789336#M63152

Power Automate Rename File
https://www.enjoysharepoint.com/power-automate-rename-file/

How To Round Date To Previous Or Next Specific Weekday In Excel?
https://www.extendoffice.com/documents/excel/2663-excel-roud-date-to-nearest-sunday.html

Slides and Demo Files from SPTechCon DC 2017

   Big thanks to Stacy and her crew of organizers, all of the attendees, and fellow speakers at SPTechCon DC 2017.  This was one of the best ones I’ve attended from an engagement and networking perspective.  Below are my slides and source code.  Feel free to let me know about any follow up questions or comments.

PowerApps and Microsoft Flow for Developers

GitHub link to demo project files

https://github.com/BrianTJackett/BTJ.PowerApps.AzureDBSample

Slides

Intro to Power BI for Office 365 Developers

Slides

Sample Financial Data file

http://go.microsoft.com/fwlink/?LinkID=521962

Blog posts on SMAT data report

https://aka.ms/SMAT2013BTJpart1

https://aka.ms/SMAT2013BTJpart2

      -Frog Out

Using Microsoft Flow to Start and Stop a Set of Azure VMs

   In this blog post I’ll walk through creating a Microsoft Flow flow for starting (and another for stopping) a set of Azure Resource Manager (ARM) VMs.  Note that this is not my own original work.  I implemented this based on the work of someone else I found online but can no longer find the original owner’s reference.  If you do find this elsewhere please feel free to let me know in the comments.

Background

   While it is possible to start and stop Azure VMs from the newly released Azure mobile app, most time I need to start up a set (3-5) VMs at a time for a SharePoint farm / app dev environment / etc.  I was able to find a sample someone wrote in Microsoft Flow to trigger the start / stop from the Flow mobile app.  The flow calls Azure AD to get an access token using an Azure AD app that has permissions to start / stop VMs.  The access token is then passed into a series of REST calls to start up VMs in order (usually domain controller, database server, app server, web front end, etc.)  Finally the flow will send a mobile push notification letting me know that the VMs have started.

Word of caution

   This solution embeds the client ID and client secret (essentially user name and password) for the Azure AD app which has permissions to the Azure VM.   This could be a security risk and as such should be cautioned from doing this.  Treat this sample as a proof of capability for development purposes only.  I’m continuing to explore alternatives (ex. Managed Service Identity, Azure connector in Microsoft Flow) which would increase security for this solution.  If anyone has any suggestions please feel free to let me know in the comments.

Solution – Start Azure VMs

   I won’t go into detail on each and every step as some of these are self explanatory or a repeat of others (ex. 2nd and 3rd VM to be started.)  Before going into the flow to be created, ensure you have an Azure AD app registered with permissions on the desired VMs to be started / stopped.

Register Azure AD App

   Log into the “new” Azure portal (portal.azure.com) and go into the Azure AD screen.  First click on Properties to view the directory ID.  Make note of this for future use.

image

   Click App registrations and create a new app of type “Web app / API”.

image

   Make note of the application ID (also known as client ID).

image

   Go into the Required Permissions setting for the app.  Add a permission for the “Windows Azure Service Management API”.  Choose the permission “Access Azure Service Management as organization users” which is currently in preview.

   Create a key for the Azure AD app and write this down.  You will only get to see this key once and cannot retrieve it at a later time.  If you lose the key value you will need to create a new one.

Assign access control to resource group

   Now that the Azure AD App has been registered it will need access control to the resource group (or individual Azure VMs, more administration if this option) so that the app can start / stop the desired VMs.  I granted Virtual Machine Contributor role to the Azure AD App but more fine grained controls might be possible if security concerns are a factor.

image

Microsoft Flow sample

  1. Manually trigger a flow
  2. Get access token for Azure
  3. Parse JSON to extract access token
  4. Start VMs (in series)
  5. Push notification if successful

image

Manually trigger a flow

   This is self explanatory.  This will let you initiate the flow from Flow web portal or the Flow mobile app.

Get access token for Azure

   This step will use an HTTP POST action to the Azure AD directory where the Azure AD app is registered.  Ideally you should send a request to this URI using Postman or a similar REST endpoint testing tool to get a sample of the JSON response to be used in the following step.

image

  • Method: POST
  • Uri: https://login.microsoftonline.com/<directoryID from previous step>/oauth2/token
  • Headers
    • Content-Type: application/x-www-form-urlencoded
  • Body: resource=https://management.azure.com/&client_id=<client ID from previous step>&grant_type=client_credentials&client_secret=<client secret from previous step>

Example JSON response using Postman:

{
   “token_type”: “Bearer”,
   “expires_in”: “3599”,
   “ext_expires_in”: “0”,
   “expires_on”: “1508115492”,
   “not_before”: “1508111592”,
   “resource”: “https://management.azure.com/”,
   “access_token”: “<removed value>”
}

Parse JSON

   Either using the sample JSON response above or your own you can define the schema of the JSON to be parsed.  Specify the “Body” of the JSON response from the prior HTTP POST action.  The important element to parse out is “access_token”.

image

{

    “type”: “object”,

    “properties”: {

        …<other properties here>…,

        “access_token”: {

            “type”: “string”

        }

    }

}

Start VM REST call

   Add another HTTP POST action this time specifying the following configuration.

image

  • Method: POST
  • Uri: https://management.azure.com/subscriptions/<Azure subscription ID>/resourceGroups/<resource group name>/providers/Microsoft.Compute/virtualMachines/<Azure VM name>/start?api-version=2016-04-30-preview
  • Headers
    • Authorization: Bearer <insert the bearer token “input” from prior Parse JSON step>

   Note that I used an older version for the “api-version=” portion of query string (highlighted in green).  A newer version might also be available and compatible but I haven’t tested anything newer.

   Create as many additional HTTP POST actions that call off to additional VMs as needed.  I hand coded the Uri for each as Microsoft Flow didn’t yet support expressions and other dynamic variables when this solution was first created.  You may want to investigate those to reduce repeated syntax if possible.

Notify when VMs started

   Straight forward action with a simple notification to let me know when flow has completed.

image

Solution – Stop Azure VMs

   The steps for stopping a set of Azure VMs will be identical to the “start” flow except that stopping VMs can be done in parallel as the order is not as important.  In your own scenario the order may be important so consider that when creating your own solution.

  1. Manually trigger a flow
  2. Get Access Token for Azure
  3. Parse JSON to extract access token
  4. Stop VMs (in parallel)
  5. Push notification if successful

image

   The other important difference will be to call to “deallocate” (highlighted in red) the VM rather than “start” using the Azure Service Management API.  See example below for the HTTP POST to a VM.

Sample Execution

   As you can see from the below sample executions of both flows the start and stop of each VM can take some time (2-3 minutes) but is still an easier process of clicking one button rather than multiple clicks within the Azure Portal or mobile app.

image

image

Conclusion

   Hopefully this walkthrough will help others who are interested in automating Azure VMs to start and stop (or any other authenticated actions against Azure resources).  I’m hoping to try out additional options to remove the need to store client ID and secret within the flow.  For the time being try out this process and let me know if you have any issues.

      -Frog Out