Ped*_*uza 0 rest powershell powerbi
最近,我一直在尝试使用Power BI REST API通过调用 .ps1 程序来自动刷新某个数据集。通过遵循本教程,我能够获得此代码,如下所示:
$groupID = "me" # the ID of the group that hosts the dataset. Use "me" if this is your My Workspace
$datasetID = "MYDATASETID" # the ID of the dataset that hosts the dataset
$clientId = "MYCLIENTID"
# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
if(-not (Get-Module AzureRm.Profile)) {
Import-Module AzureRm.Profile
}
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$resourceAppIdURI = "https://analysis.windows.net/powerbi/api"
$authority = "https://login.microsoftonline.com/common/oauth2/authorize";
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")
return $authResult
}
$token = GetAuthToken
$authHeader = @{
'Content-Type'='application/json'
'Authorization'=$token.CreateAuthorizationHeader()
}
$groupsPath = ""
if ($groupID -eq "me") {
$groupsPath = "myorg"
} else {
$groupsPath = "myorg/groups/$groupID"
}
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST –Verbose
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET –Verbose
Run Code Online (Sandbox Code Playgroud)
我确保完全按照上面链接中的说明收集参数 ( groupID,clientID和datasetID)。但是,当我尝试执行此代码时,出现错误:
Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'â€Headers System.Collections.Hashtable â€Method'.
At C:\Users\me\Desktop:41 char:1
Run Code Online (Sandbox Code Playgroud)
我不太清楚发生了什么,我什至发现了一些类似的案例,但没有一个解决方案对我有用。所以,一些帮助将不胜感激。
看起来这个解决方案是从某处复制/粘贴的,并且破折号被搞砸了:
删除 中的最后 3 个破折号Invoke-RestMethod,它们看起来像破折号,但其他看起来像破折号的 unicode 符号,并将它们替换为正常的“键盘输入”符号。
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
1670 次 |
| 最近记录: |