2017-08-29 2 views
0

Je suis en train d'importer .pbix fichier dans la collection de l'espace de travail powerbi d'azur, pour que je les commandes cli azur et powerbi cli .Comment mettre en œuvre connexion automatique sans interaction de l'utilisateur dans le portail bleu azur de VSTS à l'aide d'azur CLI & script shell puissance

script shell Power pour la connexion à portail azur et importer le fichier .pbix dans la collection de l'espace de travail powerbi azur:

Param(

#Install npm prerequisites : Azure-cli and Powerbi-cli | Y : N | Optional, default No 
[Parameter(Mandatory=$False)] [bool] $Prerequisites=$false, 

# Run the authentication process for the Azure Sub | Y : N | Optional, default No 
[Parameter(Mandatory=$True)] [bool] $Authentication=$true, 

# Name of the resource group | Ex : "MyResourceGroup" | Mandatory 
[Parameter(Mandatory=$True)] [string] $ResourceGroupName, 

# Location on Azure for the deployment | Ex : "West US" | Mandatory 
[Parameter(Mandatory=$True)] [string] $Location, 

# Name of the Workspace collection name | Ex : "MyPBIWorkspace" | Mandatory 
[Parameter(Mandatory=$True)] [string] $WorkSpaceCollectionName, 

# Id of the Power BI Workspace | Ex : "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX" | Mandatory 
[Parameter(Mandatory=$True)] [string] $WSguid, 

# Path of the PowerBI Report(.pbix) file | Ex : "E:\Users\PowerShellScriptForPowerBI" | Mandatory 
[Parameter(Mandatory=$True)] [string] $ReportsFilePath 

) 
cls 
Write-Host -BackgroundColor Black -ForegroundColor Green "##### Script launched ###### " 

if ($prerequisites) 
{ 
Write-Host -BackgroundColor Black -ForegroundColor Yellow "Installing the NPM Packages..." 
Write-Host -BackgroundColor Black -ForegroundColor Yellow "Installing Azure-CLI" 
$output = npm install azure-cli -g 
Write-Host -BackgroundColor Black -ForegroundColor Green "Azure-CLI Installed" 
Write-Host -BackgroundColor Black -ForegroundColor Yellow "Installing PowerBI-CLI" 
$output = npm install powerbi-cli -g 
Write-Host -BackgroundColor Black -ForegroundColor Green "PowerBI-CLI Installed" 
} 

if ($authentication) 
{ 
    Write-Host -BackgroundColor Black -ForegroundColor Yellow "Authentication on Azure selected..." 
    #azure login 
    #$azureAccountName ="XXXXXXXXXXXXXXXXXXXXXX" 
    #$azurePassword = ConvertTo-SecureString "XXXXXXXXXXXXXX=" -AsPlainText -Force 
    #$psCred = New-Object System.Management.Automation.PSCredential($azureAccountName, $azurePassword) 
    #Login-AzureRmAccount -C -Credential $psCred 
    #Add-AzureRmAccount -Credential $psCred -TenantId 'XXXXXXXXXXXXXXXXx' -ServicePrincipal 
    #azure login --service-principal -u "XXXXXXXXXXXXXXXX" --password "XXXXXXXXXXXxx=" --tenant "XXXXXXXXXXXXXXXXXXXXx" 
    azure account set "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 
    #azure login -u http://myClientEncryptApplication --service-principal --tenant XXXXXXXXXXXXXXXXXXXXXX 
    Write-Host -BackgroundColor Black -ForegroundColor Green "Authentication on Azure done" 
} 

try { 

Write-Host -BackgroundColor Black -ForegroundColor Yellow "Getting and storing access key..." 
#$CollectionName =$WorkSpaceCollectionName 
$accesKeyPBIJSON = azure powerbi keys list $ResourceGroupName  $WorkSpaceCollectionName --json 
$accesKeyPBIJSON = $accesKeyPBIJSON | ConvertFrom-Json 
$accesKeyPBI = $accesKeyPBIJSON.key1 
Write-Host -BackgroundColor Black -ForegroundColor Green "Acces Key stored : $accesKeyPBI" 

Write-Host -BackgroundColor Black -ForegroundColor Yellow "Importing the PBIX..." 
$path = $ReportsFilePath +"\Reports\*.pbix" 

$basename = gi $path | select basename, Name 
$filePath = $ReportsFilePath +"\Reports\" + $basename[0].Name 

$fileName = $basename[0].BaseName 

$output = powerbi import -c $WorkSpaceCollectionName -w $WSguid -k $accesKeyPBI -n "$fileName" -f "$filePath" 

Write-Host -BackgroundColor Black -ForegroundColor Green "PBIX Imported : $fileName" 
Write-Host -BackgroundColor Black -ForegroundColor Green "###### Script done ######" 
} 
catch { 
Write-Host $Error[0] -ForegroundColor 'Red' 

}

Chaque fois que je lance le script ci-dessus dans la machine locale, il sera succès connecté au portail azure mais lorsque je vérifie le code dans VSTS, l'exécution du script shell d'alimentation a échoué dans la définition de la version.

Erreur:

The subscription 'XXXXXXXXX-XXX-XXX-XXX-XXXXXX was not found. Please check your spelling, or use the azure login command to set your subscription. error: Error information has been recorded to C:\Users\buildguest.azure\azure.err

Pouvez-vous s'il vous plaît me dire comment résoudre l'erreur ci-dessus et aussi me dire comment implémenter login Automatiser dans portail bleu azur de VSTS à l'aide script shell puissance

Répondre

1

Selon votre journal des erreurs, s'il vous plaît assurez-vous que vous devez d'abord vous connecter à votre compte, e en exécuter azure account set "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX". Sur votre locale, peut-être que vous aviez connecté votre compte, vous pouvez donc exécuter azure account set "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" d'abord sans journal des erreurs.

Si vous faites cela, je vous suggère de vous connecter à votre compte avec le service principal. Veuillez vous référer à ce link pour créer un nouveau service principal.

azure login --service-principal -u "displayNamee" -p "password " --tenant "cliet id" 
azure account set "*********************" 

enter image description here

+0

Merci @Walter, le problème de connexion a été résolu. Mais je suis confronté au problème comme "npm WARN obsolète [email protected]: Utiliser uuid module à la place", quand j'exécute cette commande npm install powerbi-cli -g. Pouvez-vous s'il vous plaît me dire comment résoudre cette erreur? – pradeep

+0

@pradeep Oui, je rencontre le même journal des erreurs avec vous. Il semble question de powerbi. Désolé je ne travaille pas avec ceci, mais j'essaye de trouver la raison fondamentale. –

0

Pour connexion et en sélectionnant un abonnement, vous pouvez essayer ci-dessous.

ASM: Import-AzurePublishSettingsFile Select-AzureSubscription

ARM: Connexion-AzureRmAccount Select-AzureRMSubscription

connexions non-interactives sont détaillées here

+0

Le journal d'erreur est de 'jeu de compte d'azur "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' pas de PowerShell. –