Run reports on your tenant using the CLI for Microsoft and Azure Container Instances

Published Jun 15 2021 01:50 AM 1,551 Views

Using the CLI for Microsoft 365, you can manage your Microsoft 365 tenant and SharePoint Framework projects on any platform, including running it in a container. By running the CLI for Microsoft 365 in a container you free yourself from installing it locally. Leveraging a Logic App, Azure Container Instances and the CLI for Microsoft 365 you can automate reporting and maintenance of your tenant.

 

The goal is thus to generate some form of reporting on our tenant. There are a lot of sample scripts available, but we will start simple by reporting all deleted Office 365 Groups (this will include deleted Teams). Executing a report like that with the CLI for Microsoft 365 would be just a single line:  

 

 

m365 aad o365group recyclebinitem list

 

 

To achieve our reporting scenario we need the a few other components as well:

  1. An Azure resource group to group our resources together 
  2. A managed identity to make sure we can access our tenant securely;
  3. A Logic App to orchestrate everything;
  4. Azure Container Instances to execute our script;
  5. A Git repo that contains the script we want to execute and pull in;

If you are new to running Azure Containers and using Logic Apps there is a great walkthrough on running sentiment analysis with Azure Container Instances. But let us get started with the first step.

Create an Azure Resource Group

To create a new Azure resource group simply log in to the Azure Portal and create a new resource group using the create a resource button. For demo purposes I called my resource group cli-test.

Create a Managed Identity

In our resource group we can create a new user managed identity that we can use. Click on the add button and search for User Assigned Managed Identity to create the new managed identity. Simply provide a name and create your new managed identity. 

 

cli-ma.png

 

 

 

Once the managed identity is created it still need permissions to do anything. Just creating it is not enough. In order to use the managed identity we need to make sure that it has the correct permissions. The CLI for Microsoft 365 docs explain in details what the steps are required. For our reporting scenario's we need support to query the Graph and SharePoint. You can use the CLI for Microsoft 365 to easily hand out the permissions you need with the following snippet: 

 

 

m365 aad approleassignment add --displayName "ma-cli-test" --resource "Microsoft Graph" --scope "Sites.Read.All"
m365 aad approleassignment add --displayName "ma-cli-test" --resource "Office 365 SharePoint Online" --scope "Sites.Manage.All"
m365 aad approleassignment add --displayName "ma-cli-test" --resource "Microsoft Graph" --scope "Group.Read.All" 

 

 

Now all we need is the GUID that identifies the managed identity. Navigate to https://portal.azure.com select Azure Active Directory and pick Enterprise Applications. In the Application Filter filter on Managed Identities and make sure to pick the Application Id of your newly created managed identity. 

 

cli-ma-id.png

Store it somewhere save as we need it at a later moment. 

Create a Logic App

As we need a Logic App to orchestrate the execution of our script the first step is to create one. You can do so in any resouce group, or create a new one. There are no requirements for your Logic App. So we pick a Logic App (Consumption) and provide a resource group and name. Once the Logic App is created navigate to it and click the edit button. Once in edit mode you are free to pick your trigger. You can pick any trigger you like, for demo purposes you could connect it to a list in SharePoint Online, or just use a HTTP trigger. The next step is to create two parameters, containerGroup and containerName. Both will be used more than once so it helps to create them parameters, but it is not required. For demo purposes I added a small snippet as a postfix to identify when it was created: 

 

formatDateTime(utcNow(),'MM-dd-yyyy')

 

 This helps when debugging as you can always identify when something was created. The next step is to add a new action of type Create or update a container group. It is a pretty complex action with a lot of parameters to get right, so it is worth to pay close attention when typing:

Option  Value Comments
Subscription id Any subscription you like I suggest putting it all in the same subscription. 
Resource Group Any resource group you like  I suggest putting it all in the same resource group.
Container Group Name
@{variables('containerGroup')}
Parameter for ease of use
Container Group Location Any location is supported  
Container Name - 1
@{variables('containerName')}
Parameter for ease of use
Container Image - 1
m365pnp/cli-microsoft365:latest
 
Container Resource Requests CPU - 1 1 If you are planning to run complex or large scripts it might be worth to add additional resources. 
Container Resource Requests Memory - 1 1.5 If you are planning to run complex or large scripts it might be worth to add additional resources. 
Container Command Segment - 1
bash
You cannot execute multiple commands in a single line. You will need to add each statement to a segment. 
Container Command Segment - 2
/mnt/repo1/test.sh
The value of the mount path and script name are dependant on settings below. 
Container Volume Mount Path - 1 /mnt/repo1  
Container Volume Mount Name - 1 gitrepo The name for the mount path must match the volume name specified later. 
Volume Git Repo Volume Repository - 1 https://github.com/appieschot/cli-test.git Any public repository will do. 
Volume Name - 1 gitrepo  
ContainerGroup Managed Identity User Assigned Identities {
"/subscriptions/[guid]/resourcegroups/[rg-name]/providers/microsoft.managedidentity/userassignedidentities/[identity-name]": {}
}
Make sure to update the bold parts.
ContainerGroup Restart Policy OnFailure Make sure the container is restarted if there are problems. 

This action will thus create a new container instance, pulls in the CLI for Microsoft 365 image and make sures that a git repo with a script is pulled in. And best of all; the container created will be running with the managed identity you have specified. Now all we need to do is to capture the output of our container instance and clean up. 

 

To do so add a action of type until. Do not configure any requirements yet and simply add an action of type Get properties of a container to retrieve the latest status, use the containerGroup parameter to make sure you get the correct container. Put in the Container Group name as a parameter and check for status Succeeded of the untill action. Add a new condition and check there for the same status. In the true statement we can implement the logic for retrieving our data. You can use the Get logs from a container instance and e-mail the output to yourself. 

cli-la-cleanup.png

In the false branche add an wait action that waits for 10 or 15 seconds. That will make sure it takes a while before it retries checking the status to see if it is finished.  

Create your script

The last part is to make sure that the test.sh file referred to as being mounted in your container actually exists. It should contain all logic to run your script, but the first step is to authenticate. In order to authenticate with the managed identity we need to tell the CLI for Microsoft 365 to do so. By specifying the login using the authType parameter we can pass the GUID of our managed identity. The CLI then knows to use the managed identity of the container it is running in and you are done. 

 

 

m365 login --authType identity --userName 00000000-0000-0000-0000-000000000000 
m365 aad o365group recyclebinitem list --output json

 

 

Full Logic App

Once all these components are in place you can simply run any script in the container. Just make sure you have the appropriate permissions assigned to the Manged Identity! 

PnP Recording

If you are looking at a video walkthrough you can checkout the PnP recording. It highlights the results and steps taken to achieve basic reporting on your tenant. 

%3CLINGO-SUB%20id%3D%22lingo-sub-2377851%22%20slang%3D%22en-US%22%3ERun%20reports%20on%20your%20tenant%20using%20the%20CLI%20for%20Microsoft%20and%20Azure%20Container%20Instances%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2377851%22%20slang%3D%22en-US%22%3E%3CP%3EUsing%20the%20CLI%20for%20Microsoft%20365%2C%20you%20can%20manage%20your%20Microsoft%20365%20tenant%20and%20SharePoint%20Framework%20projects%20on%20any%20platform%2C%20including%20running%20it%20in%20a%20container.%20By%20running%20the%20CLI%20for%20Microsoft%20365%20in%20a%20container%20you%20free%20yourself%20from%20installing%20it%20locally.%20Leveraging%20a%20Logic%20App%2C%20Azure%20Container%20Instances%20and%20the%20CLI%20for%20Microsoft%20365%20you%20can%20automate%20reporting%20and%20maintenance%20of%20your%20tenant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20goal%20is%20thus%20to%20generate%20some%20form%20of%20reporting%20on%20our%20tenant.%20There%20are%20a%20lot%20of%20%3CA%20title%3D%22CLI%20for%20Microsoft%20365%20sample%20scripts%22%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fcli-microsoft365%2Fsample-scripts%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Esample%20scripts%20available%3C%2FA%3E%2C%20but%20we%20will%20start%20simple%20by%20reporting%20all%20deleted%20Office%20365%20Groups%20(this%20will%20include%20deleted%20Teams).%20Executing%20a%20report%20like%20that%20with%20the%20CLI%20for%20Microsoft%20365%20would%20be%20just%20a%20single%20line%3A%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Em365%20aad%20o365group%20recyclebinitem%20list%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20achieve%20our%20reporting%20scenario%20we%20need%20the%20a%20few%20other%20components%20as%20well%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EAn%20Azure%20resource%20group%20to%20group%20our%20resources%20together%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3EA%20managed%20identity%20to%20make%20sure%20we%20can%20access%20our%20tenant%20securely%3B%3C%2FLI%3E%0A%3CLI%3EA%20Logic%20App%20to%20orchestrate%20everything%3B%3C%2FLI%3E%0A%3CLI%3EAzure%20Container%20Instances%20to%20execute%20our%20script%3B%3C%2FLI%3E%0A%3CLI%3EA%20Git%20repo%20that%20contains%20the%20script%20we%20want%20to%20execute%20and%20pull%20in%3B%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EIf%20you%20are%20new%20to%20running%20Azure%20Containers%20and%20using%20Logic%20Apps%20there%20is%20a%20great%20%3CA%20title%3D%22running%20sentiment%20analysis%20with%20Azure%20Container%20Instances%26nbsp%3B%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-gb%2Fsamples%2Fazure-samples%2Faci-logicapps-integration%2Faci-logicapps-integration%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ewalkthrough%20on%26nbsp%3Brunning%20sentiment%20analysis%20with%20Azure%20Container%20Instances%3C%2FA%3E.%20But%20let%20us%20get%20started%20with%20the%20first%20step.%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3ECreate%20an%20Azure%20Resource%20Group%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3ETo%20create%20a%20new%20Azure%20resource%20group%20simply%20log%20in%20to%20the%20Azure%20Portal%20and%20create%20a%20new%20resource%20group%20using%20the%20%3CSTRONG%3Ecreate%20a%20resource%3C%2FSTRONG%3E%20button.%20For%20demo%20purposes%20I%20called%20my%20resource%20group%20%3CEM%3Ecli-test%3C%2FEM%3E.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3ECreate%20a%20Managed%20Identity%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EIn%20our%20resource%20group%20we%20can%20create%20a%20new%20user%20managed%20identity%20that%20we%20can%20use.%20Click%20on%20the%20%3CSTRONG%3Eadd%3C%2FSTRONG%3E%20button%20and%20search%20for%20%3CSTRONG%3EUser%20Assigned%20Managed%20Identity%20%3C%2FSTRONG%3Eto%20create%20the%20new%20managed%20identity.%20Simply%20provide%20a%20name%20and%20create%20your%20new%20managed%20identity.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22cli-ma.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287158i3798606F0854681C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22cli-ma.png%22%20alt%3D%22cli-ma.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20the%20managed%20identity%20is%20created%20it%20still%20need%20permissions%20to%20do%20anything.%20Just%20creating%20it%20is%20not%20enough.%20In%20order%20to%20use%20the%20managed%20identity%20we%20need%20to%20make%20sure%20that%20it%20has%20the%20correct%20permissions.%20The%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fcli-microsoft365%2Fuser-guide%2Fusing-own-identity%2F%23configure-api-permissions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ECLI%20for%20Microsoft%20365%20docs%3C%2FA%3E%20explain%20in%20details%20what%20the%20steps%20are%20required.%20For%20our%20reporting%20scenario's%20we%20need%20support%20to%20query%20the%20Graph%20and%20SharePoint.%20You%20can%20use%20the%20CLI%20for%20Microsoft%20365%20to%20easily%20hand%20out%20the%20permissions%20you%20need%20with%20the%20following%20snippet%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Em365%20aad%20approleassignment%20add%20--displayName%20%22ma-cli-test%22%20--resource%20%22Microsoft%20Graph%22%20--scope%20%22Sites.Read.All%22%0Am365%20aad%20approleassignment%20add%20--displayName%20%22ma-cli-test%22%20--resource%20%22Office%20365%20SharePoint%20Online%22%20--scope%20%22Sites.Manage.All%22%0Am365%20aad%20approleassignment%20add%20--displayName%20%22ma-cli-test%22%20--resource%20%22Microsoft%20Graph%22%20--scope%20%22Group.Read.All%22%20%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20all%20we%20need%20is%20the%20GUID%20that%20identifies%20the%20managed%20identity.%20Navigate%20to%20%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fportal.azure.com%3C%2FA%3E%26nbsp%3Bselect%20%3CSTRONG%3EAzure%20Active%20Directory%3C%2FSTRONG%3E%20and%20pick%20%3CSTRONG%3EEnterprise%20Applications%3C%2FSTRONG%3E.%20In%20the%20Application%20Filter%20filter%20on%20%3CSTRONG%3EManaged%20Identities%3C%2FSTRONG%3E%20and%20make%20sure%20to%20pick%20the%20%3CSTRONG%3EApplication%20Id%3C%2FSTRONG%3E%20of%20your%20newly%20created%20managed%20identity.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22cli-ma-id.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F288466iB87F18CB4EBF773F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22cli-ma-id.png%22%20alt%3D%22cli-ma-id.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EStore%20it%20somewhere%20save%20as%20we%20need%20it%20at%20a%20later%20moment.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3ECreate%20a%20Logic%20App%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EAs%20we%20need%20a%20Logic%20App%20to%20orchestrate%20the%20execution%20of%20our%20script%20the%20first%20step%20is%20to%20create%20one.%20You%20can%20do%20so%20in%20any%20resouce%20group%2C%20or%20create%20a%20new%20one.%20There%20are%20no%20requirements%20for%20your%20Logic%20App.%20So%20we%20pick%20a%20%3CSTRONG%3ELogic%20App%20(Consumption)%20%3C%2FSTRONG%3Eand%20provide%20a%20resource%20group%20and%20name.%20Once%20the%20Logic%20App%20is%20created%20navigate%20to%20it%20and%20click%20the%20%3CSTRONG%3Eedit%3C%2FSTRONG%3E%20button.%20Once%20in%20edit%20mode%20you%20are%20free%20to%20pick%20your%20trigger.%20You%20can%20pick%20any%20trigger%20you%20like%2C%20for%20demo%20purposes%20you%20could%20connect%20it%20to%20a%20list%20in%20SharePoint%20Online%2C%20or%20just%20use%20a%20HTTP%20trigger.%20The%20next%20step%20is%20to%20create%20two%20parameters%2C%20%3CSTRONG%3EcontainerGroup%3C%2FSTRONG%3E%20and%20%3CSTRONG%3EcontainerName%3C%2FSTRONG%3E.%20Both%20will%20be%20used%20more%20than%20once%20so%20it%20helps%20to%20create%20them%20parameters%2C%20but%20it%20is%20not%20required.%20For%20demo%20purposes%20I%20added%20a%20small%20snippet%20as%20a%20postfix%20to%20identify%20when%20it%20was%20created%3A%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3EformatDateTime(utcNow()%2C'MM-dd-yyyy')%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%26nbsp%3BThis%20helps%20when%20debugging%20as%20you%20can%20always%20identify%20when%20something%20was%20created.%20The%20next%20step%20is%20to%20add%20a%20new%20action%20of%20type%20%3CSTRONG%3ECreate%20or%20update%20a%20container%20group%3C%2FSTRONG%3E.%20It%20is%20a%20pretty%20complex%20action%20with%20a%20lot%20of%20parameters%20to%20get%20right%2C%20so%20it%20is%20worth%20to%20pay%20close%20attention%20when%20typing%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CTABLE%20border%3D%221%22%20width%3D%22100%25%22%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2244px%22%3E%3CFONT%20size%3D%224%22%3E%3CSTRONG%3EOption%26nbsp%3B%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2244px%22%3E%3CFONT%20size%3D%224%22%3E%3CSTRONG%3EValue%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2244px%22%3E%3CFONT%20size%3D%224%22%3E%3CSTRONG%3EComments%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3ESubscription%20id%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EAny%20subscription%20you%20like%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EI%20suggest%20putting%20it%20all%20in%20the%20same%20subscription.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EResource%20Group%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EAny%20resource%20group%20you%20like%26nbsp%3B%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EI%20suggest%20putting%20it%20all%20in%20the%20same%20resource%20group.%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3EContainer%20Group%20Name%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%40%7Bvariables('containerGroup')%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3EParameter%20for%20ease%20of%20use%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2257px%22%3EContainer%20Group%20Location%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2257px%22%3EAny%20location%20is%20supported%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2257px%22%3E%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3EContainer%20Name%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%40%7Bvariables('containerName')%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3EParameter%20for%20ease%20of%20use%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3EContainer%20Image%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Em365pnp%2Fcli-microsoft365%3Alatest%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2283px%22%3E%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3EContainer%20Resource%20Requests%20CPU%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3E1%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3EIf%20you%20are%20planning%20to%20run%20complex%20or%20large%20scripts%20it%20might%20be%20worth%20to%20add%20additional%20resources.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3EContainer%20Resource%20Requests%20Memory%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3E1.5%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3EIf%20you%20are%20planning%20to%20run%20complex%20or%20large%20scripts%20it%20might%20be%20worth%20to%20add%20additional%20resources.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3EContainer%20Command%20Segment%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ebash%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22192px%22%3EYou%20cannot%20execute%20multiple%20commands%20in%20a%20single%20line.%20You%20will%20need%20to%20add%20each%20statement%20to%20a%20segment.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3EContainer%20Command%20Segment%20-%202%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3E%2Fmnt%2Frepo1%2Ftest.sh%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3EThe%20value%20of%20the%20mount%20path%20and%20script%20name%20are%20dependant%20on%20settings%20below.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EContainer%20Volume%20Mount%20Path%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3E%2Fmnt%2Frepo1%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3E%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3EContainer%20Volume%20Mount%20Name%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3Egitrepo%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3EThe%20name%20for%20the%20mount%20path%20must%20match%20the%20volume%20name%20specified%20later.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EVolume%20Git%20Repo%20Volume%20Repository%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fappieschot%2Fcli-test.git%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fappieschot%2Fcli-test.git%3C%2FA%3E%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2284px%22%3EAny%20public%20repository%20will%20do.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2257px%22%3EVolume%20Name%20-%201%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2257px%22%3Egitrepo%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%2257px%22%3E%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3EContainerGroup%20Managed%20Identity%20User%20Assigned%20Identities%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3E%7B%3CBR%20%2F%3E%22%2Fsubscriptions%2F%3CSTRONG%3E%5Bguid%5D%3C%2FSTRONG%3E%2Fresourcegroups%2F%5Brg-name%5D%2Fproviders%2Fmicrosoft.managedidentity%2Fuserassignedidentities%2F%3CSTRONG%3E%5Bidentity-name%5D%3C%2FSTRONG%3E%22%3A%20%7B%7D%3CBR%20%2F%3E%7D%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22138px%22%3EMake%20sure%20to%20update%20the%20%3CSTRONG%3Ebold%3C%2FSTRONG%3E%20parts.%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22111px%22%3EContainerGroup%20Restart%20Policy%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22111px%22%3EOnFailure%3C%2FTD%3E%0A%3CTD%20width%3D%2233.333333333333336%25%22%20height%3D%22111px%22%3EMake%20sure%20the%20container%20is%20restarted%20if%20there%20are%20problems.%26nbsp%3B%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3EThis%20action%20will%20thus%20create%20a%20new%20container%20instance%2C%20pulls%20in%20the%20CLI%20for%20Microsoft%20365%20image%20and%20make%20sures%20that%20a%20git%20repo%20with%20a%20script%20is%20pulled%20in.%20And%20best%20of%20all%3B%20the%20container%20created%20will%20be%20running%20with%20the%20managed%20identity%20you%20have%20specified.%20Now%20all%20we%20need%20to%20do%20is%20to%20capture%20the%20output%20of%20our%20container%20instance%20and%20clean%20up.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20do%20so%20add%20a%20action%20of%20type%20%3CSTRONG%3Euntil%3C%2FSTRONG%3E.%20Do%20not%20configure%20any%20requirements%20yet%20and%20simply%20add%20an%20action%20of%20type%20%3CSTRONG%3EGet%20properties%20of%20a%20container%3C%2FSTRONG%3E%26nbsp%3Bto%20retrieve%20the%20latest%20status%2C%20use%20the%20%3CSTRONG%3EcontainerGroup%3C%2FSTRONG%3E%26nbsp%3Bparameter%20to%20make%20sure%20you%20get%20the%20correct%20container.%20Put%20in%20the%20Container%20Group%20name%20as%20a%20parameter%20and%20check%20for%20status%20%3CSTRONG%3ESucceeded%20%3C%2FSTRONG%3Eof%20the%20untill%20action.%20Add%20a%20new%20condition%20and%20check%20there%20for%20the%20same%20status.%20In%20the%20true%20statement%20we%20can%20implement%20the%20logic%20for%20retrieving%20our%20data.%20You%20can%20use%20the%20%3CSTRONG%3EGet%20logs%20from%20a%20container%20instance%3C%2FSTRONG%3E%20and%20e-mail%20the%20output%20to%20yourself.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22cli-la-cleanup.png%22%20style%3D%22width%3A%20525px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F288482i9B5AB92362145240%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22cli-la-cleanup.png%22%20alt%3D%22cli-la-cleanup.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EIn%20the%20false%20branche%20add%20an%20wait%20%3CSTRONG%3Eaction%3C%2FSTRONG%3E%20that%20waits%20for%2010%20or%2015%20seconds.%20That%20will%20make%20sure%20it%20takes%20a%20while%20before%20it%20retries%20checking%20the%20status%20to%20see%20if%20it%20is%20finished.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3ECreate%20your%20script%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EThe%20last%20part%20is%20to%20make%20sure%20that%20the%20test.sh%20file%20referred%20to%20as%20being%20mounted%20in%20your%20container%20actually%20exists.%20It%20should%20contain%20all%20logic%20to%20run%20your%20script%2C%20but%20the%20first%20step%20is%20to%20authenticate.%20In%20order%20to%20authenticate%20with%20the%20managed%20identity%20we%20need%20to%20tell%20the%20CLI%20for%20Microsoft%20365%20to%20do%20so.%20By%20specifying%20the%20login%20using%20the%20authType%20parameter%20we%20can%20pass%20the%20GUID%20of%20our%20managed%20identity.%20The%20CLI%20then%20knows%20to%20use%20the%20managed%20identity%20of%20the%20container%20it%20is%20running%20in%20and%20you%20are%20done.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Em365%20login%20--authType%20identity%20--userName%2000000000-0000-0000-0000-000000000000%20%0Am365%20aad%20o365group%20recyclebinitem%20list%20--output%20json%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3EFull%20Logic%20App%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EOnce%20all%20these%20components%20are%20in%20place%20you%20can%20simply%20run%20any%20script%20in%20the%20container.%20Just%20make%20sure%20you%20have%20the%20appropriate%20permissions%20assigned%20to%20the%20Manged%20Identity!%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3EPnP%20Recording%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EIf%20you%20are%20looking%20at%20a%20video%20walkthrough%20you%20can%20checkout%20the%20PnP%20recording.%20It%20highlights%20the%20results%20and%20steps%20taken%20to%20achieve%20basic%20reporting%20on%20your%20tenant.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIFRAME%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2Fe36qPG9x0C0%22%20width%3D%22560%22%20height%3D%22315%22%20frameborder%3D%220%22%20allowfullscreen%3D%22allowfullscreen%22%20title%3D%22YouTube%20video%20player%22%20allow%3D%22accelerometer%3B%20autoplay%3B%20clipboard-write%3B%20encrypted-media%3B%20gyroscope%3B%20picture-in-picture%22%3E%3C%2FIFRAME%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2377851%22%20slang%3D%22en-US%22%3E%3CP%3EUsing%20the%20CLI%20for%20Microsoft%20365%2C%20you%20can%20manage%20your%20Microsoft%20365%20tenant%20and%20SharePoint%20Framework%20projects%20on%20any%20platform%2C%20including%20running%20it%20in%20a%20container.%20By%20running%20the%20CLI%20for%20Microsoft%20365%20in%20a%20container%20you%20free%20yourself%20from%20installing%20it%20locally.%20Leveraging%20a%20Logic%20App%2C%20Azure%20Container%20Instances%20and%20the%20CLI%20for%20Microsoft%20365%20you%20can%20automate%20reporting%20and%20maintenance%20of%20your%20tenant.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2377851%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHow%20to%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Jun 15 2021 02:05 AM
Updated by:
www.000webhost.com