Happy June folks! I come to you with another post, but this time I wanted to change it up and show you something else I have just finished working on. As a SysAdmin, one of the most common issues we run into is managing licenses. Working at a post-secondary institution makes this an even greater challenge, as you have both students, staff and faculty constantly coming as well as going. Managing to keep up with this constant change can introduce great administrative overhead which takes away time from important upkeep of other systems and initiatives. You may also notice this same issue in large corporations or in other government organizations. To help combat this, I wanted to create a flow that can do the following:
- Get the user and their licenses
- Determine their last sign-in and the date
- Conditional to determine if the user is past the "cutoff" date
- Remove the user from a group where the license is assigned
General Information
- Scheme: HTTPS
- Host: graph.microsoft.com
- Base URL: /v1.0
Security
- AuditLog.Read.All
- Directory.Read.All
- User.ReadWrite.All
- Authentication Type: OAuth 2.0
- Identity Provider: Azure Active Directory
- Client ID: add your Client ID
- Client secret: add your secret that you generated from the app registration
- Authorization URL: https://login.microsoftonline.com
- Tenant ID: add your tenant ID. This can be found in the Azure Portal under "Tenant Properties"
- Resource URL: https://graph.microsoft.com
- Enable on-behalf-of login: false
- Scope: Directory.Read.All User.ReadWrite.All AuditLog.Read.All
- Redirect URL: this will be generated when you save the custom connector.
Creating the Definitions
https://graph.microsoft.com/v1.0/users/{userId}/licenseDetails
This in turn will give you the following result:
{"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users()/licenseDetails","@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET users('<guid>')/licenseDetails?$select=servicePlans,skuId","value": [{"id": "gHe4LsjI706Gy7mIO8jPohyUoe1PPJVJtevoWkIXWrk","skuId": "eda1941c-3c4f-4995-b5eb-e85a42175ab9","skuPartNumber": "POWERAUTOMATE_ATTENDED_RPA","servicePlans": [{"servicePlanId": "375cd0ad-c407-49fd-866a-0bff4f8a9a4d","servicePlanName": "POWER_AUTOMATE_ATTENDED_RPA","provisioningStatus": "Success","appliesTo": "User"}..............
The ID that is highlighted is the operation ID that is required to complete this action. Take note of it, and then create a new action with the following information:
- Summary: License PA Connector - Get Licenses
- Description: This request retrieves all licenses for the user account.
- Operation ID: Insert the Operation ID provided
- Visibility: none
https://graph.microsoft.com/v1.0/users/{userId}
This should result in us being able to get the other operation ID which we can then insert into our second action with the following parameters:
- Summary: License PA Connector - Get Last Sign In
- Description: This request retrieves user's last sign-in
- Operation ID: Insert the Operation ID provided
The path and $select should also populate automatically. If not, then ensure that the path and query fields contain the following:
- Path: userId
- Query: $select (this will be useful later)