Creating your first workflow: a practical example

  • Last update on January 23rd, 2024

Workflow exercise: Remove guest accounts

The goal of this exercise is to set up a workflow that is going to remove automatically guest user accounts that are at least six months old and have been inactive for more than 180 days, on a weekly basis. 

In this exercise, you will see:

  • How to create a workflow
  • How to configure an execution input
  • How to add and configure an action
  • How to publish a workflow
  • How to schedule a workflow on a custom policy

The exercise is divided into two parts: in the first, we will create the workflow, while in the second, we will schedule it to a custom policy in a playbook that we will specifically create.

You can use the interactive tutorial or follow the step-by-step guide in the accordions.

First part: how to create a workflow

Step 1: create a new workflow

The first step is to create a workflow that includes an action to remove guest users.
For further information, refer to the article: Create a workflow.

  1. Click on the “ACTIONS” tab on the sidebar.  
  2. Click “Manage workflows”.
  1. Select “Workflows”.  
  2. Select “Create new”.
 
 

Step 2: configure execution input

Now let's configure “execution inputs”, also referred to as input variables, which are essential data points required to initiate the workflow.
For further information, refer to the article: Configure execution inputs.

  1. Click the pencil icon and type the name “Remove guest user accounts in the “Name” field.
  2. (Optional): Click the “Description” button below the name of the workflow to add a description.
  3. Click “Configure execution input”, then click “Add execution input” on the next page.
  1. Under “Target“, select “User” from the drop-down menu.
  2. Search for “UserPrincipalName” in the list and click on it.
  3. Make sure the “is Required” box is checked.
  4. Click “Save”. 

At this point, you have specified and created the required execution input for your workflow. 

 
 

Step 3: add and configure an action

After setting execution inputs, we can add actions, which are the individual tasks that make up a workflow.
For further information, refer to the article: Adding workflows actions.

  1. In the “Add“ drop-down, click the “Add action” button.   
  1. In the “Action“ category, select “User”.
  2. In the “Select action” drop-down, select “Remove guest user”.
  3. Under “Settings”, click on the lightning icon to the right of the User Principal Name field.     
    Choose the "UserPrincipalName" input that you previously created from the displayed list.
  4. Click “Save.
 
 

Step 4: publish a workflow

Let's save our workflow first as a draft, and then publish it.
For further information, refer to the article: Publish.

  1. Click “Save” at the top right. This will save your workflow as a draft.
    Then, click “Publish” at the top right: this will publish your workflow and make it available to you, and everyone you grant access to it.

 
 

Second part: how to add to a playbook

Step 5: schedule a workflow on a custom policy

A workflow can be scheduled on a custom policy. We will create a custom policy from a report and then associate the workflow with it to use it as the remediation action.
For further information, refer to the article: Create a custom policy from a report.

  1. Go to “REPORTS” > “USERS” > “Guest users”.
  2. Display the columns “Last Microsoft 365 activity date” and “Creation date”, along with the “User principal name” column, which will supply the execution input for the workflow.
  3. Add the filter “Not in last N days” = 180 to both the “Creation date“ and the “Last Microsoft 365 activity date” columns.
  1. Select “Actions“ and click “Create Custom Policy”. 

  1. Fill out all the required fields: “Name”, “Description”, “Category”, and “Playbooks”.

  1. Set the desired threshold. This will trigger a warning when there are matched items. For further information, refer to the article: Thresholds.

  1. Under “Remediation action” choose “Run workflow” as a remediation and select your workflow from the drop-down. For further information, refer to the article: Remediation settings and actions.
  2. Under ”Remediation execution input”, click on “Automap” to automatically generate the input. 
  3. Under “Schedule”, specify how often you would like the workflow to be executed.

When selecting the columns for the report, ensure that you have chosen the column that will supply the execution input for the workflow; otherwise, the Automap button will not function! 

 

  1. Review and ”Save”.

  1. Under ”PLAYBOOKS”, you should be able to see your new custom policy with scheduled remediation.