This article is a continuation of my previous blog post, where I listed practical areas around designing a governance strategy to secure your Power Platform components. In this article, I focus on automation of administrative tasks that you would normally perform manually from the Admin Centers (Power Apps and Power Platform).
Earlier this year, Microsoft launched possibilities to automate management and monitoring of assets on the Power Platform by providing a library of PowerShell functions (cmdlets) that can be executed from an Azure VM or local windows computer. This feature is still in preview mode as per official documentation. PowerShell cmdlets are simple functions that helps to retrieve information on different Power Platform assets and also perform common operational tasks on those assets.
These functions are available in a library under two different groups or categories Administrator CMDlets library and Maker CMDlets library. These cmdlets can be combined with other Power Shell functions to write complex PowerShell scripts to automate administrative and operational tasks on the Power Platform.
Note: In order to execute the Administrator cmdlets, the users do not need to be Office 365 tenant Admin, but the cmdlets executed are limited to the Power Platform Assets (PowerApps, Power Automate Flows etc.) they own.
Now, in the next section we go through a step by step guide for a basic setup for PowerShell Cmdlets for Power Platform and for execution of some sample PowerShell cmdlets. For a very detailed requirements on licensing and security roles for executing the PowerShell cmdlets for PowerApps please refer the official documentation.
PowerShell Cmdlets Libraries Setup
1. From Search Menu look for ‘PowerShell’ and choose the option as shown in image under and right click to run it as administrator.
2. Next on the PowerShell console, you need to type the following commands to install the Cmdlets library on your local machine
- Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
- Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber
Note, that when you run the commands, you will be prompted to confirm it. Just Type Y to confirm the installations.
3. Next you once the basic setup of installing the libraries are done, you need to execute the following command to login in the Power Platform environment with two possibilities:
- Standard Azure AD Login Screen
- Supplying Azure AD username and password in the common itself
$pass = ConvertTo-SecureString “password” -AsPlainText -Force
Add-PowerAppsAccount -Username firstname.lastname@example.org -Password $pass
Screen shots of the first authentication option stated earlier that I used in this example is shown below.
4. In addition to the earlier setup steps, you can also install a help library for the CMDlets with the following command and shown in image below. The help library offers a number of commands that can be used to get help documentation on PowerShell cmdlets for Power Platform assets also shown as marked in below image.
Once the help library is installed you can execute it for getting help for PowerShell cmdlets as shown in samples example below where I used it with the ‘Get AdminPowerAppEnvironment’ cmdlet.
- Get-Help Get-AdminPowerAppEnvironment -Examples
- Get-Help Get-AdminPowerAppEnvironment -Detailed
Operational tasks that can be performed using the PowerShell cmdlets for PowerApps are categorized into different operations areas. These areas contain cmdlets that are designed to replicate the manual setup of executing tasks through the PowerApp admin center.
5. To get a list of all the environments under the Office 365 tenant, execute the cmdlet as shown in the image below.
Sample Scenario For Automation
In the below example, I want to list all the PowerApps in my tenant and then marked one of the PowerApp as Featured App (a way to group PowerApps and it shows up at the top of the list PowerApp mobile player). The steps for accomplishing this task via PowerShell cmdlets are shown below:
1.To get a list of all PowerApps under the default environment, I used the cmdlet
This cmlet lists all the PowerApps under the default environment along with Display Name and App Name (Unique GUID) and other attributes associated with the PowerApp such as IsFeatured App, IsHeroApp, Owner, Created Time etc. as shown in image below.
2. Next, I used the following Cmdlet to mark one of my PowerApp (formprocessordemo) as a Featured App. Note that I needed the unique name for the PowerApp (GUID).
Set-AdminPowerAppAsFeatured –AppName ‘AppName’
3. Once, this cmdlet is executed, I run the PowerShell cmdlet for getting the updated properties for my sample PowerApp (formprocessordemo)
Here, I can see that now the PowerApp IsFeatured property is true as shown below.
I highly recommend to read these below listed white papers (PDF links) from Microsoft released earlier this year for a very deep dive into the Power Platform governance.
If you are keen to know how to better govern your organization’s Power Apps / Power Platform environments or need help to build an internal Power Platform governance strategy for your organization, please don’t hesitate to contact me at email@example.com / +4746726207.