简体   繁体   English

我需要什么 vscode 扩展来运行这个 powershell 代码?

[英]What vscode extensions do I need to run this powershell code?

The below powershell script acquires an authtoken and refreshes all Power BI datasets with a call to the Power BI rest api.下面的 powershell 脚本获取一个 authtoken 并通过调用 Power BI rest api 刷新所有 Power BI 数据集。 The script works fine in powershell ISE but won't run in vscode.该脚本在 powershell ISE 中运行良好,但无法在 vscode 中运行。 I have tried installing several Azure extensions to no avail.我试过安装几个 Azure 扩展无济于事。 I am relatively new to both vscode and powershell and could use some advice on how to move on from here.我对 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
    }
}

According to your error message, it seems you are facing with module assembly dependency conflicts.根据您的错误消息,您似乎正面临模块程序集依赖冲突。

Please check your .NET Core version in VS Code.请在 VS Code 中检查您的 .NET Core版本

Here is a similar issue with module assembly dependency conflicts you can refer to.这是您可以参考的模块程序集依赖冲突的类似问题

In NETCoreApp 1.0 and 1.1 the Microsoft.NETCore.Portable.Compatibility package added support for mscorlib-based portable class libraries.在 NETCoreApp 1.0 和 1.1 中,Microsoft.NETCore.Portable.Compatibility 包添加了对基于 mscorlib 的可移植类库的支持。 These class libraries have the same reference assembly names as some desktop assemblies: mscorlib, system, system.core, etc, but their versions match the lowest version of all supported frameworks for the portable profiles: silverlight.这些类库与某些桌面程序集具有相同的引用程序集名称:mscorlib、system、system.core 等,但它们的版本与所有支持的可移植配置文件框架的最低版本相匹配:silverlight。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM