Forum Discussion
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("https://dev.azure.com/MYCOMPANY/{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
$content.Add($streamContent)
$Importresponse = $httpClient.PostAsync($uriImport, $content).Result
$stream.Dispose()
$stream.Close()
$content.Dispose()
this what the initial response looks like, when I get the file from our azure repo