Note: This question is specific to the usage of the Get-Report cmdlet, less so on calling the REST API to download the report (which there are existing message threads on).
That appears to be a .net method instead of a cmdlet. And it takes a byte array, instead of a response variable, say, from Get-Report.
The specific challenge I’m facing is how to write the PDF file as a binary file. Getting and writing/saving a CSV report doesn’t have the same challenge.
For example the following returns an arraylist object of count 1 into the pdf variable:
get-report -TaskResultId [someId] -FileFormat pdf -OutVariable pdf -ReturnType application/pdf -verbose
Then I do a pdf[0] to get the first element, but at this point, the returned element seems to be in some string / ASCII format, with text like ??? where its content is literally just ??? and not binary anymore.
Hi @RandomUser4096 This method is used to write byte arrays to files in .NET, which is applicable in PowerShell when handling binary data.
$reportID = "<someID>"
$filePath = "C:\path\to\your\Report.pdf"
Retrieve the report in PDF format
try {
$pdfContent = Get-Report -TaskResultId $reportID -FileFormat pdf
Check if the content is valid
if ($pdfContent -ne $null -and $pdfContent.Length -gt 0) {
# Save the PDF content to a file
[System.IO.File]::WriteAllBytes($filePath, $pdfContent)
Write-Output "Report successfully saved to $filePath"
} else {
Write-Output "The report content is empty or null."
}
} catch {
Write-Error "An error occurred while retrieving or saving the report: $_"
}
I appreciate your attempts at responding…but none of the above responses has yield a solution nor a step forward unfortunately, and seems to miss the mark each time.
ReadAllBytes reads from a file, not from a string variable:
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
I’ll re-iterate: Issue is with writing the response from Get-Report to a file as binary data…because the response from Get-Report seems to be string / ASCII(?).
Also, before I started this thread, I’ve tested with getting CSV reports…and able to save them to files without issue. Text / ASCII reports are fine. Issue is specifically with writing / saving binary PDF from the returned data of Get-Report cmdlet.
(When you try to open / view the saved PDF report from Get-Report, it does NOT render correctly…indicating file content issue. If you call the API directly, that report seems fine.)
Hi @RandomUser4096 , that’s good, would it be okay with you to do share the Get-Report file and clean any sensitive information. I can have a look and test it
That’s another challenge it itself…The report (in string) is corrupted, so I can’t securely / correctly scrub sensitive information from it for it to be shared.
Do you not run into the same issue on your end when downloading a PDF report with Get-Report cmdlet? Or are you shooting in the dark with no environment access on your end?
So you’ll not see the issue as you’re running in silo without the PowerShell SDK. You need the PSSailPoint module loaded, and link up to a tenant in order to see the issue.
The issue I’m facing is specifically with Get-Report, not how to read / write binary files in PowerShell in the generic sense.
@RandomUser4096 I found a solution to this. I too noticed that writing to PDFs was problematic. My workaround was to not use the Get-Reports cmdlet and instead use Invoke-RestMethod so that you can utilize the -outfile parameter.
Yeah, the API isn’t the issue. It’s the Get-Report cmdlet not being able to store a usable PDF file.
The PowerShell SDK has been somewhat buggy in my IDN / ISC journey…
You would think there would be a validation step in the test suite of the SDK to verify if the output is actually usable. Or maybe we are the implied automated testers.