Showing results for 
Search instead for 
Did you mean: 
SandMonster Frequent Visitor
Frequent Visitor

Help importing a pbix file to my workspace using powershell

Hi all, I am currently working with powershell, trying to create a routine to get a pbix file from our azure git repo, and I have been able to get the file without problems, the thing is... I am having problems trying to import the file to my workspace using powershell, the reason is, when I get access to my file the response returns a string which is, I assume, the decoded version of the file, so, when I try to encode it back and send it to my workspace I get an error "Bad request" and that's it, does anyone have a clue on how to correctly encode the file and import it?? 


Note: When I do it locally, getting a file from a local path, I don't have problems importing files/adding multipartformdatacontent. 


Thanks in advance and here's a sample of my code.


 $blob =  [string]::Format("{0}/_apis/git/repositories/{1}/blobs/{fileId}?api-version=5.0", {projectName}, {repositoryID})

 $file = Invoke-RestMethod -Uri $blob -Method Get -Headers $header -ContentType "application/octet-stream" 

                $enc = [system.Text.Encoding]::UTF8.GetBytes($file)
                $stream =  New-Object System.IO.MemoryStream (,$enc)
                $bytecontent = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue "form-data"
                $bytecontent.Name = "uploadFile";
                $bytecontent.FileName = "uploadFile.pbix";
                $streamContent = New-Object System.Net.Http.StreamContent $stream
                $streamContent.Headers.ContentDisposition = $bytecontent
                $content = New-Object System.Net.Http.MultipartFormDataContent

$Importresponse = $httpClient.PostAsync($uriImport, $content).Result        


image.pngthis what the initial response looks like, when I get the file from our azure repo

Helpful resources


How to Get Your Question Answered Quickly

Power BI Super User, Greg Deckler, explains

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Ideas
Top Kudoed Authors
Users Online
Currently online: 27 members 783 guests
Please welcome our newest community members: