is it even possible to use Microsoft.PowerApps.Administration.PowerShell in an Azure Runbook?

Guy Martinello 20 Reputation points
2024-11-07T18:07:26.64+00:00
Import-Module Microsoft.PowerApps.Administration.PowerShell 
Import-Module Microsoft.PowerApps.PowerShell 


#Add-PowerAppsAccount #Use for desktop..[desktop works.  It returns the filtered environment]

#Use for Azure Automation Account
Add-PowerAppsAccount -Endpoint prod  -TenantID '.....-81d1-419f-......' -ClientSecret '....secretkeyvalue...' -ApplicationId '.....-a431-40bc-......' 


[array]$environments = Get-AdminPowerAppEnvironment | Where-Object {$_.DisplayName -like "*default*"}
[array]$environments =Get-AdminPowerAppEnvironment -Filter ".....-a4c6-eff9-a402-....."
write-output $environments[0].DisplayName
Get-Help Get-AdminPowerAppEnvironment

App Registration API permissions

User's image

The call to Add-PowerAppsAccount causes no error. The call to Get-Help returns the help docs The call to Get-AdminPowerAppEnvironment, with either | Where-Object .... or -Filter results in nothing

Is it possible to make this work?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,278 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,706 questions
{count} votes

Accepted answer
  1. Rahul Podila 895 Reputation points Microsoft Vendor
    2024-11-08T06:54:52.94+00:00

    Hi @Guy Martinello
    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here. 

    You seem to be able to log in but not provide the environment, and this is most likely due to a licensing issue. First, make sure your account has the proper permissions to access your environment. If you are using a regular user account, ensure that the environment you want to access has environment administrator permissions. Using a service account (such as a service principal) also requires environment administrator permission. You can go to the Power Platform Admin Center and see if you are registered as an admin of a community. If not, ask your admin for necessary permission. 

    Also, make sure your witness is actually in your surroundings. Go to the Power Platform Admin Center and look under "Environments" to see if any environments are listed. If there isn’t one, you have to create one. 

    If there is a region, try to rerun the command without using any filters and see if you can find any regions listed. You can do this by running: 
    $environments = Get-AdminPowerAppEnvironment

    $environments | Format-Table DisplayName, EnvironmentName, EnvironmentId

    This gives you a list of all the environments you can access. If nothing shows up, you can also check for any error messages by running the command and typing $Error[0] to see if there is a specific problem. 
    If you have any further queries, do let us know  

    ---------------------------------------------------------------------------------------------------------  

     If the answer is helpful, please click "Accept Answer" and "Upvote it" 


1 additional answer

Sort by: Most helpful
  1. Guy Martinello 20 Reputation points
    2024-12-04T09:26:40.3833333+00:00

    Thank you all very much for you help.

    In the end, the permissions that I showed above were correct - or at least not wrong.

    What was missing was the following code that had to be executed by our tenant admin

    $appId = "CLIENT_ID_FROM_AZURE_APP" # Login interactively with a tenant administrator for Power Platform Add-PowerAppsAccount -Endpoint prod -TenantID $tenantId # Register a new application, this gives the SPN / client application same permissions as a tenant admin New-PowerAppManagementApp -ApplicationId $appId	
    

    https://zcusa.951200.xyz/en-us/powershell/module/microsoft.powerapps.administration.powershell/new-powerappmanagementapp?view=pa-ps-latest

    Thank you all for you help with this!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.