通过Powershell进行Power BI编程刷新数据集

时间:2019-02-28 07:57:43

标签: powershell powerbi

我正在尝试调度(Windows任务管理器)powershell脚本来刷新Power BI数据集。 我正在尝试使用时间表(Windows任务管理器)powershell脚本来刷新Power BI数据集。

$groupID = "me" # the ID of the group that hosts the dataset. Use "me" if this is your My Workspace

$datasetID = "11111111-1111-1111-1111-111111111111" # the ID of the dataset that hosts the dataset

$clientId = "11111111-1111-1111-1111-111111111111" # AAD Client ID

# Load Active Directory Authentication Library (ADAL) Assemblies
$adal = "${env:ProgramFiles}\WindowsPowerShell\Modules\Microsoft.ADAL.Powershell\1.12\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "${env:ProgramFiles}\WindowsPowerShell\Modules\Microsoft.ADAL.Powershell\1.12\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal)
[System.Reflection.Assembly]::LoadFrom($adalforms)

# Set Azure AD Tenant name
$adTenant = "Tenant.onmicrosoft.com" 

# Set redirect URI for Azure PowerShell
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"

# Set Resource URI to Azure Service Management API
$resourceAppIdURI = "https://management.core.windows.net/"

# Set Authority to Azure AD Tenant
$authority = "https://login.windows.net/$adTenant"

# Set user credentials (*** obviously you wouldn't have the password in clear text in a production script ***)
$userName = "admin@Tenant.onmicrosoft.com"
$userPassword = ConvertTo-SecureString -String "password" -AsPlainText -Force
$userCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$userName", $userPassword

# Create AuthenticationContext tied to Azure AD Tenant
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority

# Acquire token
$authResult = $authContext.AcquireToken($resourceAppIdURI,$clientId,$userCredential, "Auto")

# Get the auth token from AAD
$token = $authResult

# Building Rest API header with authorization token
$authHeader = @{
   'Content-Type'='application/json'
   'Authorization'=$token.CreateAuthorizationHeader()
}

# properly format groups path
$groupsPath = ""
if ($groupID -eq "me") {
    $groupsPath = "myorg"
} else {
    $groupsPath = "myorg/groups/$groupID"
}

# Refresh the dataset
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri -Headers $authHeader –Method POST –Verbose

# Check the refresh history
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET –Verbose

但是我遇到两个错误:

  

新对象:找不到“ PSCredential”的重载,并且参数计数:“ 2”字符串:75位置:14

  

方法调用失败,因为[Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContex]不包含名为“ AcquireToken”的方法。字符串:79位置:5

我认为第二个错误取决于第一个错误。任何成见如何解决问题?

0 个答案:

没有答案