下面的powershell脚本获取一个身份验证令牌,并通过调用Power BI rest api刷新所有Power BI数据集。该脚本可以在Powershell ISE中正常运行,但不能在vscode中运行。我尝试安装多个Azure扩展均无济于事。我对vscode和powershell都比较陌生,可以就如何从此处继续使用一些建议。
# https://technovert.com/refreshing-all-datasets-in-power-bi-using-rest-api/
# https://github.com/Azure-Samples/powerbi-powershell/blob/master/manageRefresh.ps1
$clientId = “78xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxa4” #Client Id of the registered app.
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/"
}
$uril = "https://api.powerbi.com/v1.0/$groupsPath"
$restResponse1 = Invoke-RestMethod -Uri $uril -Headers $authHeader -Method GET
$x=$restResponse1.value
Write-Host "`n"
foreach($i in $x) {
$groupID=$i.Id #workspace Id
$groupName = $i.Name #Workspace name
#$groupName + "-" + $groupID
Write-Host "Refreshing Workspace: $groupName, Id: $groupID `n" -ForegroundColor Yellow
$uri = "https://api.powerbi.com/v1.0/$groupsPath/$groupID/datasets"
$restResponse = Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET
$d=$restResponse.value
foreach($j in $d) {
$datasetID=$j.Id #dataset Id
$datasetName=$j.Name #dataset Name
#$datasetName + "-" + $datasetID
Write-Host " Refreshing dataset: $datasetName, Id: $datasetID `n"
# Refresh the dataset
$uri = "https://api.powerbi.com/v1.0/$groupsPath/$groupID/datasets/$datasetID/refreshes"
$postResponse = Invoke-RestMethod -Uri $uri -Headers $authHeader -Method POST
Start-Sleep -s 10
# Check the refresh history
$uri = "https://api.powerbi.com/v1.0/$groupsPath/$groupID/datasets/$datasetID/refreshes"
$getResponse = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET
Start-Sleep -s 30
}
}
答案 0 :(得分:1)
根据您的错误消息,看来您正面临module assembly dependency conflicts.
请在VS Code中检查您的.NET Core 版本。
这里是一个similar issue,带有模块程序集相关性冲突,您可以参考。
在NETCoreApp 1.0和1.1中,Microsoft.NETCore.Portable.Compatibility 软件包增加了对基于mscorlib的可移植类库的支持。 这些类库与某些类具有相同的参考程序集名称 桌面程序集:mscorlib,system,system.core等,但是它们 版本与所有受支持框架的最低版本匹配 便携式配置文件:silverlight。