Forum Discussion

BoNDoK00's avatar
BoNDoK00
Frequent Visitor
3 years ago

PowerShell authentication with service Principal failing

 

 

$client_id = <ClientID>
$tenant_id =  <SecretID>
$secret =  <Secret>


$SecurePassword = ConvertTo-SecureString $secret -Force -AsPlainText
$servicePrincipal = New-Object -TypeName PSCredential -ArgumentList $client_id, $SecurePassword

Connect-PowerBIServiceAccount -ServicePrincipal -Credential $servicePrincipal -Environment Public -Tenant $tenant_id

 

 

returns 

Environment : Public
TenantId :
ClientId : <ClientID>
Password : ********

 

As you can see tenantid is returned as empty.  When I try to call APIs I get this error message:

 

 

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:1
+ Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/adm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod

 

 

 What am I doing wrong? 

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi BoNDoK00 

    What kind of API are you using and can you provide the API you are using for testing ?

     

    Best Regards,
    Community Support Team _ Ailsa Tao
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • BoNDoK00's avatar
      BoNDoK00
      Frequent Visitor
      Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/admin/groups/<GROUPID>/users' -Method Get

      Please note that my app has the following permissions:

       

       

  • BoNDoK00's avatar
    BoNDoK00
    Frequent Visitor

     

    Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/admin/groups/<GROUPID>/users' -Method Get

    Please note that my app has the following permissions: