<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic 'Post in group' with powershell in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Post-in-group-with-powershell/m-p/3030399#M40796</link>
    <description>&lt;P&gt;I need to import some files to Power BI using API and powershell&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I create a temporary upload with:&amp;nbsp;groups/group_id/imports/createTemporaryUploadLocation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I push my file to the URL&lt;/P&gt;&lt;P&gt;Invoke-RestMethod -Method PUT -Uri \"${url}\" -Header @{ \'x-ms-blob-type\' = \'BlockBlob\'; \'Content-Length\' = $len } -InFile '$myFile' -TimeoutSec 3600&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, I try to import that URL to PowerBi using:&lt;/P&gt;&lt;P&gt;Invoke-WebRequest -Method POST -Uri "&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/group_id/imports?datasetDisplayName=$myFile&amp;amp;nameConflict=Overwrite" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/group_id/imports?datasetDisplayName=$myFile&amp;amp;nameConflict=Overwrite&lt;/A&gt;" -Header @{Authorization = '$Token'; 'Content-Length' = $len} -Body '{ "fileUrl"= "url"}' | ConvertTo-Json -Depth 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting the following error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Invoke-WebRequest : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What am I doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;After some more research, I found the bellow powershell code to import to PowerBI. It is working but it won't let me import larger file 900,000KB&lt;/P&gt;&lt;P&gt;I also still need to find out how to get the files from azure...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12&lt;/P&gt;&lt;P&gt;$localPath = ''&lt;BR /&gt;$graphToken = ''&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;$groupId&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;$importMode="CreateOrOverwrite"&lt;BR /&gt;if(!$ReportName){&lt;BR /&gt;$ReportName = (Get-Item -LiteralPath $localPath).BaseName&lt;BR /&gt;}&lt;BR /&gt;if($groupId){&lt;BR /&gt;$uri = "&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode&lt;/A&gt;"&lt;BR /&gt;}else{&lt;BR /&gt;$uri = "&lt;A href="https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode&lt;/A&gt;"&lt;BR /&gt;}&lt;BR /&gt;$boundary = "---------------------------" + (Get-Date).Ticks.ToString("x")&lt;BR /&gt;$boundarybytes = [System.Text.Encoding]::ASCII.GetBytes("`r`n--" + $boundary + "`r`n")&lt;BR /&gt;$request = [System.Net.WebRequest]::Create($uri)&lt;BR /&gt;$request.ContentType = "multipart/form-data; boundary=" + $boundary&lt;BR /&gt;$request.Method = "POST"&lt;BR /&gt;$request.KeepAlive = $true&lt;BR /&gt;$request.Headers.Add("Authorization", "Bearer $graphToken")&lt;BR /&gt;$rs = $request.GetRequestStream()&lt;BR /&gt;$rs.Write($boundarybytes, 0, $boundarybytes.Length);&lt;BR /&gt;$header = "Content-Disposition: form-data; filename=`"temp.pbix`"`r`nContent-Type: application / octet - stream`r`n`r`n"&lt;BR /&gt;$headerbytes = [System.Text.Encoding]::UTF8.GetBytes($header)&lt;BR /&gt;$rs.Write($headerbytes, 0, $headerbytes.Length);&lt;BR /&gt;$fileContent = [System.IO.File]::ReadAllBytes($localPath)&lt;BR /&gt;$rs.Write($fileContent,0,$fileContent.Length)&lt;BR /&gt;$trailer = [System.Text.Encoding]::ASCII.GetBytes("`r`n--" + $boundary + "--`r`n");&lt;BR /&gt;$rs.Write($trailer, 0, $trailer.Length);&lt;BR /&gt;$rs.Flush()&lt;BR /&gt;$rs.Close()&lt;BR /&gt;Write-Host $request&lt;BR /&gt;$response = $request.GetResponse()&lt;BR /&gt;$stream = $response.GetResponseStream()&lt;BR /&gt;$streamReader = [System.IO.StreamReader]($stream)&lt;BR /&gt;$content = $streamReader.ReadToEnd() | convertfrom-json&lt;BR /&gt;$jobId = $content.id&lt;BR /&gt;$streamReader.Close()&lt;BR /&gt;$response.Close()&lt;BR /&gt;$header = @{&lt;BR /&gt;'Authorization' = 'Bearer ' + $graphToken}&lt;/P&gt;&lt;P&gt;Write-Host $("Deployment request has been created: " + $content.id)&lt;BR /&gt;while($true){&lt;BR /&gt;$res = Invoke-RestMethod -Method GET -uri "&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports/$jobId" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports/$jobId&lt;/A&gt;" -UseBasicParsing -Headers $header&lt;/P&gt;&lt;P&gt;if($res.ImportState -ne "Publishing"){&lt;BR /&gt;Return "Deployment completed with the following status: " + $res.ImportState&lt;BR /&gt;}&lt;BR /&gt;Sleep -s 5&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jan 2023 18:12:31 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-01-19T18:12:31Z</dc:date>
    <item>
      <title>'Post in group' with powershell</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Post-in-group-with-powershell/m-p/3030399#M40796</link>
      <description>&lt;P&gt;I need to import some files to Power BI using API and powershell&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I create a temporary upload with:&amp;nbsp;groups/group_id/imports/createTemporaryUploadLocation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I push my file to the URL&lt;/P&gt;&lt;P&gt;Invoke-RestMethod -Method PUT -Uri \"${url}\" -Header @{ \'x-ms-blob-type\' = \'BlockBlob\'; \'Content-Length\' = $len } -InFile '$myFile' -TimeoutSec 3600&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, I try to import that URL to PowerBi using:&lt;/P&gt;&lt;P&gt;Invoke-WebRequest -Method POST -Uri "&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/group_id/imports?datasetDisplayName=$myFile&amp;amp;nameConflict=Overwrite" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/group_id/imports?datasetDisplayName=$myFile&amp;amp;nameConflict=Overwrite&lt;/A&gt;" -Header @{Authorization = '$Token'; 'Content-Length' = $len} -Body '{ "fileUrl"= "url"}' | ConvertTo-Json -Depth 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting the following error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Invoke-WebRequest : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What am I doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;After some more research, I found the bellow powershell code to import to PowerBI. It is working but it won't let me import larger file 900,000KB&lt;/P&gt;&lt;P&gt;I also still need to find out how to get the files from azure...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12&lt;/P&gt;&lt;P&gt;$localPath = ''&lt;BR /&gt;$graphToken = ''&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;$groupId&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;$importMode="CreateOrOverwrite"&lt;BR /&gt;if(!$ReportName){&lt;BR /&gt;$ReportName = (Get-Item -LiteralPath $localPath).BaseName&lt;BR /&gt;}&lt;BR /&gt;if($groupId){&lt;BR /&gt;$uri = "&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode&lt;/A&gt;"&lt;BR /&gt;}else{&lt;BR /&gt;$uri = "&lt;A href="https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName=$ReportName&amp;amp;nameConflict=$importMode&lt;/A&gt;"&lt;BR /&gt;}&lt;BR /&gt;$boundary = "---------------------------" + (Get-Date).Ticks.ToString("x")&lt;BR /&gt;$boundarybytes = [System.Text.Encoding]::ASCII.GetBytes("`r`n--" + $boundary + "`r`n")&lt;BR /&gt;$request = [System.Net.WebRequest]::Create($uri)&lt;BR /&gt;$request.ContentType = "multipart/form-data; boundary=" + $boundary&lt;BR /&gt;$request.Method = "POST"&lt;BR /&gt;$request.KeepAlive = $true&lt;BR /&gt;$request.Headers.Add("Authorization", "Bearer $graphToken")&lt;BR /&gt;$rs = $request.GetRequestStream()&lt;BR /&gt;$rs.Write($boundarybytes, 0, $boundarybytes.Length);&lt;BR /&gt;$header = "Content-Disposition: form-data; filename=`"temp.pbix`"`r`nContent-Type: application / octet - stream`r`n`r`n"&lt;BR /&gt;$headerbytes = [System.Text.Encoding]::UTF8.GetBytes($header)&lt;BR /&gt;$rs.Write($headerbytes, 0, $headerbytes.Length);&lt;BR /&gt;$fileContent = [System.IO.File]::ReadAllBytes($localPath)&lt;BR /&gt;$rs.Write($fileContent,0,$fileContent.Length)&lt;BR /&gt;$trailer = [System.Text.Encoding]::ASCII.GetBytes("`r`n--" + $boundary + "--`r`n");&lt;BR /&gt;$rs.Write($trailer, 0, $trailer.Length);&lt;BR /&gt;$rs.Flush()&lt;BR /&gt;$rs.Close()&lt;BR /&gt;Write-Host $request&lt;BR /&gt;$response = $request.GetResponse()&lt;BR /&gt;$stream = $response.GetResponseStream()&lt;BR /&gt;$streamReader = [System.IO.StreamReader]($stream)&lt;BR /&gt;$content = $streamReader.ReadToEnd() | convertfrom-json&lt;BR /&gt;$jobId = $content.id&lt;BR /&gt;$streamReader.Close()&lt;BR /&gt;$response.Close()&lt;BR /&gt;$header = @{&lt;BR /&gt;'Authorization' = 'Bearer ' + $graphToken}&lt;/P&gt;&lt;P&gt;Write-Host $("Deployment request has been created: " + $content.id)&lt;BR /&gt;while($true){&lt;BR /&gt;$res = Invoke-RestMethod -Method GET -uri "&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports/$jobId" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/$groupId/imports/$jobId&lt;/A&gt;" -UseBasicParsing -Headers $header&lt;/P&gt;&lt;P&gt;if($res.ImportState -ne "Publishing"){&lt;BR /&gt;Return "Deployment completed with the following status: " + $res.ImportState&lt;BR /&gt;}&lt;BR /&gt;Sleep -s 5&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 18:12:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Post-in-group-with-powershell/m-p/3030399#M40796</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-01-19T18:12:31Z</dc:date>
    </item>
  </channel>
</rss>

