Azure Automation: Cannot Authenticate from Powerapps module

Jorge Rodrigues 181 Reputation points
2020-08-03T16:47:58.773+00:00

Hello,

I'm trying to use the powerapps administration module (https://www.powershellgallery.com/packages/Microsoft.PowerApps.Administration.PowerShell/2.0.72) inside an Azure Runbook.
However when I try to authenticate using:

> $pass = ConvertTo-SecureString "password" -AsPlainText -Force
> Add-PowerAppsAccount -Username foo@zamir1 .com -Password $pass

I get the following error:
Add-PowerAppsAccount : Method invocation failed because
[Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext] does not contain a method named 'AcquireToken'.
At line:115 char:1

  • Add-PowerAppsAccount -Endpoint prod -Username $username -Password $se ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (:) [Add-PowerAppsAccount], RuntimeException
  • FullyQualifiedErrorId : MethodNotFound,Add-PowerAppsAccount

The module is available from the Modules Gallery so I would assume it works.

I have tried the same from my machine and it works without issues so it seems the issue is azure automation.

From searching in google I found some people referring to iphlpapi.dll being outdated on azure automation.

How can I authenticate so I can use the module? Is there any alternative?

Thanks in advance.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,113 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,361 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. olufemia-MSFT 2,861 Reputation points
    2020-08-04T00:21:13.59+00:00

    Hello rodjorge , can you confirm the PowerApps module has been imported to your Azure automation account?

    You have a few options to import the module - assuming this has not been done.

    1. Navigate to the module link you shared, click tab "Azure Automation" and deploy to the desired Automation account as shown below. 15346-importpwrapp.png
    2. Import via Azure Portal. 15363-importportal.png
    0 comments No comments

  2. Jorge Rodrigues 181 Reputation points
    2020-08-04T07:56:25.773+00:00

    Hello @olufemia-MSFT

    yes, I have imported both powerapps modules.

    The issue is when I use Add-PowerAppsAccount inside the runbook, outside on my pc it works correctly.

    I have seen in this page that some users have issues authenticating to AAD from azure runbooks, could it be the same issue?

    https://stackoverflow.com/questions/36680829/adal-and-azure-automation