powerbi-powershell: Login-PowerBI -Credential $cred does not work in Azure Automation

This code doesn’t work in Azure Automation: Login-PowerBI -Credential $mycreds

The reason it doesn’t work is that it’s calling WindowsAuthenticationFactory.InitializeCache which tries to start a process. https://github.com/microsoft/powerbi-powershell/blob/master/src/Common/Common.Authentication/WindowsAuthenticationFactory.cs

That may make sense for interactive login popups, but for passing -Credential it shouldn’t be interactive. (I don’t think -Credential currently supports multi-factor auth logins.)

To prove launching a process is the culprit, the following code in a Azure Automation Runbook (PowerShell) will cause it to fail and be suspended after 3 retries just like the Login-PowerBI -Credential $cred code does:

$ps = new-object System.Diagnostics.Process
$ps.StartInfo.Filename = "ipconfig.exe"
$ps.StartInfo.Arguments = " /all"
$ps.StartInfo.RedirectStandardOutput = $True
$ps.StartInfo.UseShellExecute = $false
$ps.start() | Out-Null
$ps.WaitForExit()
[string] $Out = $ps.StandardOutput.ReadToEnd();
$Out

To also prove you can’t run an executable inside Azure Automation, see this link:

https://feedback.azure.com/forums/246290-automation/suggestions/31957750-can-we-execute-exe-or-bat-files-inside-runbook

The reason I’m trying to do credential auth is because service principal auth doesn’t currently have access to classic workspaces I believe.

Please enhance the Login-PowerBI cmdlet to avoid launching a process when you use the -Credential parameter only.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 31 (1 by maintainers)

Most upvoted comments

@kartikjindgar I’m using the following two lines to authenticate from a runbook:

$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-PowerBIServiceAccount -Tenant "4********************5" -ServicePrincipal -ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint