Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Create streaming dataset from powershell script

Hi All, I am trying to build a streaming dataset using power shell script.  On powershell doc there is not this option: Add-PowerBIDataset (MicrosoftPowerBIMgmt.Data) | Microsoft Docs On the othe...
  • SpartaBI's avatar
    SpartaBI
    4 years ago

    Hi Anonymous,

    Your code looks fine except for the way you pass the JSON value. You can use:

     

    # User credential
    $User = "[email protected]"
    $Pword = ConvertTo-SecureString –String 'bL3JZOyTDU' –AsPlainText -Force
    $Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Pword
    
    # Connect to AAD
    $AzureProfile = Connect-AzAccount -Credential $Credential
    
    # Get an AccessToken to the Power BI service
    $AccessTokenDetails = Get-AzAccessToken -ResourceUrl 'https://analysis.windows.net/powerbi/api' -DefaultProfile $AzureProfile
    
    $Headers = @{
        'Authorization' = "Bearer $($AccessTokenDetails.Token)"
    }
    
    $Url = "https://api.powerbi.com/v1.0/myorg/datasets?defaultRetentionPolicy=basicFIFO"
    $Body = '{
      "name": "SalesMarketing",
      "defaultMode": "Push",
      "tables": [
        {
          "name": "Product",
          "columns": [
            {
              "name": "ProductID",
              "dataType": "Int64"
            }
          ]
        }
      ]
    }'
    
    Invoke-RestMethod -Method 'Post' -Headers $Headers -Uri $Url -Body $body -ContentType 'application/json'

     


    This worked for me.






    Showcase Report – Contoso By SpartaBI