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

Get-GSDriveFileList -Recurse doesn't always recurse #308

Open FISHMANPET opened 4 years ago

FISHMANPET commented 4 years ago

The recurse flag works by looking at all the folders returned from the original query, and then recurses into them without the original query string. This would work if you just wanted all the files in a directory and ran the command without a filter. However if you're running it with a filter that doesn't include mimeType = 'application/vnd.google-apps.folder' your original query won't return any folders, and there won't be anything to for it to recurse through.

I tagged this as both a bug and an enhancement. I'm guessing based on the existing logic, the use case you envisioned was getting every file in a directory structure. In that case, I would say specifying a Filter with -Recurse isn't a supported use case, and the bug is in allowing both of those parameters to be used together. The Bugfix for that would be to setup parameter sets so they can't be used together.

However, my use case is looking for a specific file somewhere in a tree structure, and that's where the enhancement would come in. What I'm thinking is if both a filter and -Recurse is specified, run two searches, one with the filter on the parent and another to get all the folders within the parent. For every returned folder, basically do the same thing. Run the original query against that folder, plus run another query to get all the folders in that folder.