Я пытаюсь запустить сценарий powershell для расписания (диспетчер задач Windows) для обновления наборов данных Power BI.Я пытаюсь выполнить сценарий PowerShell для расписания (диспетчера задач Windows) для обновления наборов данных 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
Но я получаю две ошибки:
New-Object: не удается найти перегрузкудля «PSCredential» и количества аргументов: «2» строка: 75 позиция: 14
И
Ошибка вызова метода, поскольку [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContex] не содержит метод с именем «AcquireToken».строка: 79 позиция: 5
Я думаю, что вторая ошибка зависит от первой.Любые идиоты, как решить проблему?