microsoft / powerbi-powershell

PowerShell community for Microsoft PowerBI. Here you will find resources and source for PowerShell modules targeting PowerBI.
MIT License
346 stars 120 forks source link

How can I login to PowerBI Systematically ? #338

Open tamathew opened 3 years ago

tamathew commented 3 years ago

Can I get a sample script which help me login to powerbi using user account and password systematically and list all groups / workspaces associated with the user. I do not want to manually authenticate via browser. I'm using a Mac. I tried the rest api using Python, but it is not letting me to list all groups under the user. It is giving me 401 error where as if i authenticate using powershell, i can list down the groups.

CattieCat commented 3 years ago

Please checkout https://docs.microsoft.com/en-us/powershell/module/microsoftpowerbimgmt.profile/connect-powerbiserviceaccount?view=powerbi-ps . You just need to define a PSCredential variable and pass it to -Credential

On Wed, Oct 27, 2021 at 8:18 PM Thomas Mathew @.***> wrote:

Can I get a sample script which help me login to powerbi using user account and password systematically and list all groups / workspaces associated with the user. I do not want to manually authenticate via browser.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/microsoft/powerbi-powershell/issues/338, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTKWKG2LF2G47QGCKZRUPDUJC6J7ANCNFSM5G3Z22FQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

tamathew commented 3 years ago

Hi @CattieCat - I tried but got the below error Connect-PowerBIServiceAccount: One or more errors occurred. (User and password authentication is not supported in .NET Core or with DeviceCode authentication.)

I ran the below code :

$password = ConvertTo-SecureString 'pass123' -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ('root', $password) Connect-PowerBIServiceAccount -Credential $credential

CattieCat commented 3 years ago

Which version are you on? Can you try newest version? This blocker has been removed a while back.

On Wed, Oct 27, 2021, 11:34 PM Thomas Mathew @.***> wrote:

Hi @CattieCat https://github.com/CattieCat - I tried but got the below error Connect-PowerBIServiceAccount: One or more errors occurred. (User and password authentication is not supported in .NET Core or with DeviceCode authentication.)

I ran the below code :

$password = ConvertTo-SecureString 'pass123' -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ('root', $password) Connect-PowerBIServiceAccount -Credential $credential

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/powerbi-powershell/issues/338#issuecomment-953543658, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTKWKDSLBRMSHGERWN3AJDUJDVHBANCNFSM5G3Z22FQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

tamathew commented 3 years ago

PS /Users/tmathew> dotnet --list-sdks 3.1.404 [/usr/local/share/dotnet/sdk] 3.1.406 [/usr/local/share/dotnet/sdk] 5.0.402 [/usr/local/share/dotnet/sdk]

Powershell version. :

PS /Users/tmathew> $PSVersionTable

Name Value


PSVersion 7.1.5 PSEdition Core GitCommitId 7.1.5 OS Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Oct 12 18:34:05 PDT 2021; root:xnu-6153.141.43~1/RELE… Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

@CattieCat

CattieCat commented 3 years ago

I meant for upgrading MicrosoftPowerBIMgmt ;)

On Thu, Oct 28, 2021, 2:28 PM Thomas Mathew @.***> wrote:

PS /Users/tmathew> dotnet --list-sdks 3.1.404 [/usr/local/share/dotnet/sdk] 3.1.406 [/usr/local/share/dotnet/sdk] 5.0.402 [/usr/local/share/dotnet/sdk]

Powershell version. :

PS /Users/tmathew> $PSVersionTable

Name Value

PSVersion 7.1.5 PSEdition Core GitCommitId 7.1.5 OS Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Oct 12 18:34:05 PDT 2021; root:xnu-6153.141.43~1/RELE… Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/powerbi-powershell/issues/338#issuecomment-954234995, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTKWKEB5GFBPTKKJWOWEUTUJG57RANCNFSM5G3Z22FQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

tamathew commented 3 years ago

Hi @CattieCat - I have 1.2.1077 (current version) 1.2.1077 MicrosoftPowerBIMgmt PSGallery Microsoft Power BI PowerShell - All cmdlets for Microsoft Power BI

CattieCat commented 3 years ago

OK looks like it's not the issue I thought it to be. Have you ever tried service principal? Also I doubt there's a way for you to login without human interaction, because you are on Unix and device code is required for all non Windows OS. https://github.com/microsoft/powerbi-powershell/pull/92

On Thu, Oct 28, 2021 at 4:21 PM Thomas Mathew @.***> wrote:

Hi @CattieCat https://github.com/CattieCat - I have 1.2.1077 (current version) 1.2.1077 MicrosoftPowerBIMgmt PSGallery Microsoft Power BI PowerShell - All cmdlets for Microsoft Power BI

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/powerbi-powershell/issues/338#issuecomment-954294310, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTKWKABLZOJEVZYK3ZN2X3UJHLHFANCNFSM5G3Z22FQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

tamathew commented 3 years ago

I tried the below and got an error. Connect-PowerBIServiceAccount -ServicePrincipal -Credential $servicePrincipal -Environment Public -Tenant $tenant

Connect-PowerBIServiceAccount: One or more errors occurred. (Error Acquiring Token: MSAL.NetCore.4.25.0.0.MsalServiceException: ErrorCode: unauthorized_client Microsoft.Identity.Client.MsalServiceException: AADSTS700016: Application with identifier 'user_name' was not found in the directory 'company_name'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant. Trace ID: 1d1fcc18-3bda-4c15-a492-1001845b1d00 Correlation ID: d025930a-2659-49bb-8a98-607cec8d9afc Timestamp: 2021-10-29 06:40:58Z at Microsoft.Identity.Client.OAuth2.OAuth2Client.ThrowServerException(HttpResponse response, RequestContext requestContext) at Microsoft.Identity.Client.OAuth2.OAuth2Client.CreateResponse[T](HttpResponse response, RequestContext requestContext) at Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync[T](Uri endPoint, HttpMethod method, RequestContext requestContext, Boolean expectErrorsOn200OK, Boolean addCommonHeaders) at Microsoft.Identity.Client.OAuth2.OAuth2Client.GetTokenAsync(Uri endPoint, RequestContext requestContext, Boolean addCommonHeaders) at Microsoft.Identity.Client.OAuth2.TokenClient.SendHttpAndClearTelemetryAsync(String tokenEndpoint)

tamathew commented 3 years ago

hi @CattieCat - This is not even working in AZURE Powershell - cloudshell, I get the same error

Connect-PowerBIServiceAccount: One or more errors occurred. (User and password authentication is not supported in .NET Core or with DeviceCode authentication.)

CattieCat commented 3 years ago

We have other customers in Azure Runbook so I'm pretty sure it's working for most people. Can you share the exact steps for you to use Azure PowerShell? I wonder if it's another case that requires device code.

On Tue, Nov 2, 2021 at 10:39 AM Thomas Mathew @.***> wrote:

hi @CattieCat https://github.com/CattieCat - This is not even working in AZURE Powershell - cloudshell, I get the same error

Connect-PowerBIServiceAccount: One or more errors occurred. (User and password authentication is not supported in .NET Core or with DeviceCode authentication.)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/powerbi-powershell/issues/338#issuecomment-957979742, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTKWKBKM7RURR7BZ7DTLXLUKAV77ANCNFSM5G3Z22FQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

tamathew commented 3 years ago

Requesting a Cloud Shell.Succeeded. Connecting terminal...

Welcome to Azure Cloud Shell

Type "az" to use Azure CLI Type "help" to learn about Cloud Shell

MOTD: Manage Azure Active Directory: Get-Command -Module AzureAD*

VERBOSE: Authenticating to Azure ... VERBOSE: Building your Azure drive ... PS /home/thomas> $password = ConvertTo-SecureString 'pass123' -AsPlainText -Force PS /home/thomas> $credential = New-Object System.Management.Automation.PSCredential ('root', $password) PS /home/thomas> Connect-PowerBIServiceAccount -Credential $credential Connect-PowerBIServiceAccount: User and password authentication is not supported in .NET Core or with DeviceCode authentication. PS /home/thomas>

@CattieCat

jonyjesus18 commented 2 years ago

@tamathew I have the same issue as you - did you find a workaround? Thank you