Getting Started with Power Fx
Table of Contents
Getting started with Power Fx #
The following allows you to start using Power Fx within in the context of a terminal window, much like PowerShell. The guide talks through installing the CLI, adding an authorisation profile and finally connecting to the environment in which to run the Power Fx.
Commands such as Collect and Remove will add and remove data from the tables so use with caution
Installing the Power Platform CLI #
Installing the Power Platform CLI (aka pac) in VS Code is a prerequisite for this guide.
- Click the extensions icon on the far left of the VS Code console
- Once the extensions have loaded search for ‘Power Platform Tools’
- Click the Install button highlighted
Setting up Authorisation #
To access environments they need to be authorised, this is done simply in the terminal window. As the CLI is now installed new commands are available all prefixed with ‘pac auth’. Using ‘pac auth create’ allows creation of a new authorisation profile for the specified envionment by using the –environment parameter. The paramter can be supplied as an environment Id, as below. There are ways of connecting, but I have found guid or the environment url are the most reliable.
The following command allows the creation of an authorisation profile linked to the environment with an id of 11111111-2222-3333-4444-555555555555
pac auth create --environment 11111111-2222-3333-4444-555555555555
Once the command has been entered, a credentials prompt will pop. The crednetial to connect to the evironment will need to be added.
N.B. During testing I found, once a connection to an environment in a tenant has been created, that profile can be used to connect to other environments in that tenant.
The command below lists all authorisation profiles which have been set up, once run it will display all profiles, note the index number. pac auth list
To switch to different profiles another command can be used, this will make it clear as to why the index is important.
pac auth select --index 2
The command when run, switchs the profile to the chosen index.
Connecting to an Environment #
Now the correct profile has been selected, the next command connects to the environment specified again by the –environment parameter. It will the
pac power-fx repl --environment 11111111-2222-3333-4444-555555555555
From the image above Power Fx code has been added to show the date