[英]Error when trying to use Power BI REST API - Invoke-RestMethod : A positional parameter cannot be found that accepts argument
Lately I've been trying to use Power BI REST API to make the refresh of a certain dataset automatically, by calling a .ps1 program . 最近,我一直在尝试使用Power BI REST API 通过调用.ps1程序来自动刷新某些数据集。 By following this tutorial, I was able to get this code, which is addapted as you can see below:
通过遵循本教程,我可以获取此代码,可以对其进行修改 ,如下所示:
$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
I made sure to collect the parameters ( groupID
, clientID
and datasetID
) exactly as specified in the links above. 我确保完全按照上述链接中的指定收集参数(
groupID
, clientID
和datasetID
)。 However, when I try to execute this code, I get back the error: 但是, 当我尝试执行此代码时,我得到了以下错误:
Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'â€Headers System.Collections.Hashtable â€Method'.
At C:\Users\me\Desktop:41 char:1
I can't quite tell what's going on, and I even found some similar cases , but none of the solutions worked for me. 我不太清楚发生了什么,甚至发现了一些类似的案例 ,但是没有一种解决方案适合我。 So, some help would be deeply appreciated.
因此,将不胜感激一些帮助。
It looks like this solution is copy/pasted from somewhere and the dashes are screwed up: 看来此解决方案是从某处复制/粘贴的,并且破折号已拧紧:
Delete the last 3 dashes in Invoke-RestMethod
, which looks like dashes, but are other looks like dash unicode symbols, and replace them with normal "typed by the keyboard" ones. 删除
Invoke-RestMethod
的最后3个破折号,它们看起来像破折号,而其他看起来像破折号unicode符号,并用普通的“用键盘键入”的符号代替它们。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.