Skip to content

Login and retrieve token via Powershell to use for Clear-PBITableRows #62

@MarkusSacramento86

Description

@MarkusSacramento86

#Login to Power BI
$username = "[email protected]"
$password = "ENCRYPTED PASSWORD"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,($password | ConvertTo-SecureString)
Login-PowerBI -Credential $cred
#Retrieve token while logged in
$PowerBIToken = Get-PowerBIAccessToken -AsString
#Trying to clear table with retrieved token
Clear-PBITableRows -authToken $PowerBIToken -DataSetId "f666h111-e553-8f64-7428-72vr74sdf57j" -TableName "RealTimeData"
#Disconnect from Power BI
Disconnect-PowerBIServiceAccount

Above code works to login my account to Power BI.
I´ve managed to store PowerBIAccessToken to a variable.
But I can´t use that variable as token when trying to clear the data.
I recieve below error:

Invoke-PBIRequest : The remote server returned an error: (403) Forbidden. - ''
At C:\Program Files\WindowsPowerShell\Modules\PowerBIPS\PowerBIPS.psm1:1410 char:5
+ Invoke-PBIRequest -authToken $authToken -method Delete -resource ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WebException
+ FullyQualifiedErrorId : System.Net.WebException,Invoke-PBIRequest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions