usaussie / appscript-google-shared-drive-inventory

If you're a Google Workspace Super Admin, you've probably been thinking of ways to inventory and keep a handle on Google Shared Drives. They are a really great addition to the Workspace offering, but there are still some gaps in reporting & oversight that some people have wanted. This solution uses Google Apps Script and the Drive API to pull information about all the Shared Drives in a domain into a Google Sheet. Then, it uses the Drive API again to loop through all the drives and get the top-level permissions. Note, this does not traverse down into subfolders' permissions inside every shared drive. While this is entirely possible to script, the exponential size and scope of the data collected is too large to be effectively stored in a single Google Sheet (in my opinion). This solution is meant to solve two fairly basic questions: Who owns and has access to the Shared Drives in my domain? Can I perform an inventory on a schedule, so I can see how things change over time?
GNU General Public License v3.0
18 stars 2 forks source link

Only writes one row of permissions #1

Open bingaman opened 2 years ago

bingaman commented 2 years ago

You're overwriting the permissions row on each loop so it just ends up showing one permission per shared drive

https://github.com/usaussie/appscript-google-shared-drive-inventory/blob/6041c5e0eac0ea85723fe9ba94cc83d367af621a/Code.gs#L150

mjoyosa commented 1 year ago

Here's what I did to make it write all permissions:

  1. Replace: https://github.com/usaussie/appscript-google-shared-drive-inventory/blob/c32fbc3480af934b30d9f821d7a577b977a540de/Code.gs#L111 with: var lastRow = rangeData.getNumRows(); var driveCount = lastRow - 1;

  2. Use driveCount instead of the this constant: https://github.com/usaussie/appscript-google-shared-drive-inventory/blob/c32fbc3480af934b30d9f821d7a577b977a540de/Code.gs#L12 in: https://github.com/usaussie/appscript-google-shared-drive-inventory/blob/c32fbc3480af934b30d9f821d7a577b977a540de/Code.gs#L112 and in: https://github.com/usaussie/appscript-google-shared-drive-inventory/blob/c32fbc3480af934b30d9f821d7a577b977a540de/Code.gs#L119

This is will prevent the script from using a blank Drive ID for the permissions query if your Shared Drive list is fewer than the value of NUMBER_OF_ROWS_TO_LOOKUP_PERMISSIONS_PER_LOOP.

  1. This should be included in the loop at line 148 to be able to write all the permissions in the array.

https://github.com/usaussie/appscript-google-shared-drive-inventory/blob/c32fbc3480af934b30d9f821d7a577b977a540de/Code.gs#L159

usaussie commented 1 year ago

Thanks for the heads up on this issue. -- if you want to add this as a pull request, i'll review again and accept/merge it.