powershell - 使用 powershell 在线登录到 power bi 服务(静默,即没有弹出窗口)
问题描述
我想登录到 Power BI Online 服务并使用 REST API 从数据集中删除行。我的其余代码运行良好,但登录似乎不起作用。这是我尝试过的。有人能帮助我吗?谢谢!
$pbiUsername = "abc.xyz@xxx.com"
$pbiPassword = "Password"
$clientId = "a81b2cc1-4c97-2323-bal4-eeb21c4c6e46"
$body = @{"resource" = "https://analysis.windows.net/powerbi/api"
"client_id" = $clientId;
"grant_type" = "password";
"username" = $pbiUsername;
"password" = $pbiPassword;
"scope" = "openid"
}
$authUrl = "https://login.windows.net/common/oauth2/token/"
$authResponse = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
$headers = @{
"Content-Type" = "application/json";
"Authorization" = $authResponse.token_type + " " +
$authResponse.access_token
}
$restURL = "https://api.powerbi.com/v1.0/myorg/groups"
$restResponse = Invoke-RestMethod -Uri $restURL –Method GET -Headers $headers
解决方案
“登录似乎不起作用”并没有为我们提供足够的信息来提示您出了什么问题。
我会推荐你使用官方的Microsoft Power BI Cmdlet来完成这样的任务。它有很大的优势 - 您无需注册应用程序即可使用它。在这种情况下,您的代码如下所示:
Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile
$password = "Password" | ConvertTo-SecureString -asPlainText -Force
$username = "abc.xyz@xxx.com"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Connect-PowerBIServiceAccount -Credential $credential
Invoke-PowerBIRestMethod -Url 'groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/datasets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/tables/xxxxxx/rows' -Method Delete
Disconnect-PowerBIServiceAccount
推荐阅读
- c++ - 解释元组上的循环
- hive - Hive - 带有特殊字符的 LIKE 运算符
- excel - 在excel中搜索ID列表并匹配
- javascript - 在 jquery 中搜索包含元素内的元素的最快方法
- c++ - 如果我提前将参数声明为变量而不是将它们写入函数调用的行内,它有什么区别(在内存方面)?
- image - 带有 Pillow 的图像上的羽毛边缘
- java - 如何仅从命令行创建一个包含所有依赖项的 jar?
- java - 应用程序无法使用 @Async 注释启动
- compilation - 接下来我需要做什么才能让我的 g++ 编译的可执行文件在其他 Windows 机器上运行?
- php - PHP - 在递归函数中连接