Ever since Dynamics 365 became Power Platform there is always a high likelihood that someone working in Power Platform is also working in Azure. When it comes to Azure, Azure CLI or Azure PowerShell is a tool that gets used daily. In the case of Power Platform, it is Power Platform CLI (pac).
If you want to quickly run some pac commands there was no way to do this in the browser before. Since pac is a cross platform and a dotnet tool as well, you can install this in Azure Cloud Shell by running
dotnet tool install --global Microsoft.PowerApps.CLI.Tool
If you haven’t used Azure Cloud Shell before you can quickly refer the docs page: https://learn.microsoft.com/en-au/azure/cloud-shell/get-started?tabs=azurecli
After you have provisioned Azure Cloud Shell, if you create PowerShell profile as well it becomes easier to add PowerShell command to startup of the profile. You can do this by running the PS command once inside the PowerShell terminal on Azure Cloud Shell (https://learn.microsoft.com/en-us/azure/cloud-shell/cloud-shell-predictive-intellisense#how-to-create-a-powershell-profile-in-cloud-shell)
New-Item -Path $Profile -ItemType File -Force
After this you can install my pac Intellisense module by running (if needed)
Install-Module -Name PowerPlatformCLIAutoComplete
This module shows Intellisense suggestions for pac like below when you press TAB. In this case PSReadLine is in Inline completion mode.
Once this is done, you can add some commands to the profile. There is an inbuilt Monaco editor in Azure Cloud Shell which can be invoked by running
code $PROFILE
The commands that I have added are
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Import-Module -Name PowerPlatformCLIAutoComplete
You can save the file by pressing Right Click and both Save and Quit are available in the menu. Since PSReadline is already available in Azure Cloud Shell you can switch between Inline completion mode and List completion mode by pressing F2 key. Below screenshot shows PSReadLine running in List mode.
Once pac is installed you’ll need to login into your environment. You can do this by running
pac auth create -env https://[ENV].crm.dynamics.com -dc
You can also use ApplicationId, Secret to login, but I am using Device Code because I want to authenticate into the Dataverse environment with the same user account that I use in Azure.
Since Azure Cloud Shell also has a Storage Account that is mapped, you could use that as a source or target for pac. Example: you can export an unmanaged solution to the Cloud drive. So for example, if you run pac solution export –name experiments –async –path ./clouddrive/ –overwrite you will see the zip file in the Storage Account’s File share.
You can also map the Storage Account’s Cloud Drive on you local machine easily. In this case I am using the script to do this in my Windows machine.
You can also try out the new feature: Power Fx REPL.
I hope this helps you use Power Platform CLI in Azure Cloud Shell.