SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
235 stars 67 forks source link

Add -RevisionID to Export-GSDriveFile #226

Closed Foggy2 closed 5 years ago

Foggy2 commented 5 years ago

Hey @scrthq

I have finally had a chance to have a look at the file revision support that you added. Get-GSDriveRevision works well! 👍

Would it be possible to add a parameter to Export-GSDriveFile that accepts the revision ID?

Ultimately I would like to be able to download all of the revisions for a given file.

Thanks for all your help!

scrthq commented 5 years ago

Hey @Foggy2 - so, the Export method doesn't support a Revision ID, but you can simply use the -OutFilePath parameter on Get-GSDriveRevision directly to do the same thing 😄 . That being said, looking at the code and it appears that trying to download multiple revisions of the same file may cause a conflict since the revision ID is not added to the resolved file name (it's just FileName.extension). Not sure how this would work exactly with Drive specific mimetypes, e.g. Sheets files, where Export handles the mimetype conversion to the usable format.

scrthq commented 5 years ago

You can, however, specify the full path for the downloaded file and can craft your own filename using the bits from there if you'd like. It only builds the filename if the OutFilePath provided is a directory, otherwise it just uses what you set as the path.

First section builds the file name if the path provided is a directory ($outFilePathItem.PSIsContainer).

Second sets the $filePath value to the provided path if it exists and -Force was provided, first backing up the original in case of failure during download to provide a quick restore of the original file.

Third sets the $filePath value to the provide path if it simply doesn't exist at all, under the assumption that the path provided was a file path and not a directory and that the expectation was that the file does not exist yet.

image

Foggy2 commented 5 years ago

Hi @scrthq Sorry, I have been busy and nearly forgot to respond!

I tried the -OutFilePath parameter but unfortunately I was trying to download a Google Docs file. So I can confirm that currently the Drive specific mime types don't seem to work as expected.

scrthq commented 5 years ago

Hey @Foggy2 - I completely get you and I think we're a bit limited here, unfortunately =. Files.Export() is the only method that I'm aware of that allows you to export Google specific MimeTypes as standard MimeTypes and it doesn't support a Revision parameter 😞 .