Search code examples
google-drive-apigoogle-workspacegoogle-sitesgam

Is there a way to find the published URL of all owned Google Sites?


I've been using GAM to locate all google site Drive files in my workspace domain and now have a list of addresses like this:

https://sites.google.com/d/1450940359u5609586456/edit

I'm trying to find a way to locate the published URL of the drive google site file but I'm not sure it's possible. GAM does not provide the info when the drive file is interogated. I'm interested in any solution, not just based on GAM.


Solution

  • It's not currently possible to get a site's published URL using GAM. GAM relies on Google's APIs and there is not one available for new Sites:

    The Sites APIs currently support only classic Sites. These APIs do not support new Sites. -- https://support.google.com/a/answer/7181011?hl=en

    Despite Google's repeated assurances that new Sites would be able to do everything classic Sites did, seven years on this is one of a number of unfilled gaps.

    If you are only interested in sites with a "Custom URL," these can easily be viewed in the Google Workspace Admin under Apps → Google Workspace → Sites → Custom URL:

    Screenshot showing where to find Custom URL mapping

    If you want to know about all sites, there is no good solution I'm aware of. One possible workaround is to give yourself access to every single site using GAM and then inspect each Site manually or using some sort of RPA or browser scripting tool.

    Before you start down this path, generate a list of all the Sites in your domain and export it to Google Sheets (the quantity of results might help you decide how far to pursue this idea):

    gam all users show filelist todrive query "mimeType = 'application/vnd.google-apps.site'"
    

    Hint: To narrow down the scope of this and all other GAM commands listed here you may want to replace all users with ou "OU/Sub-OU" or you could audit a subset of users by adding them to a new group called [email protected] and use group sites-audit-users throughout.

    If you decide to proceed, the high level steps are:

    1. Create an "Auditor" group to use for this process
    2. Give the Auditor group edit access to all the sites in the domain
    3. Inspect all the sites (manually or automatically)
    4. Delete the Auditor group

    1. Create Auditor group and add yourself

    gam create group name "Sites Auditor - April 2023" email [email protected]
    gam update group [email protected] add owner user [email protected]
    

    2. Give the Auditor group access to all sites

    gam all users show filelist id title alternateLink query "mimeType = 'application/vnd.google-apps.site'" | tee sites.csv | gam csv - gam user ~Owner add drivefileacl ~id group [email protected] role editor
    

    Note: This uses tee to both pipe the output to the next GAM command and save it to a file called sites.csv in your current directory. Windows users may need to install a version of tee themselves for this command to work.

    3. Inspect all the sites

    The sites will all be listed in sites.csv. You can open the edit interface for each site (manually or programmatically) using the URL in the alternateLink column.

    If inspecting manually, open the "Publish settings..." screen under the "Publish" dropdown menu:

    Screenshot showing the "Publish settings..." menu option

    If inspecting using some sort of browser scripting or RPA tool such as Selenium, UIPath or Power Automate, be aware that some sites may have one or more custom URLs in addition to their "normal" URL:

    Screenshot of a site with additional custom URLs

    4. Delete the Auditor group

    Optional but thorough: Deleting the group will effectively remove the permissions from all the sites but an ACL entry for the deleted group will remain in each file. If you wish to be more thorough you should first remove the Auditor group permission from each file using the CSV we saved earlier:

    gam csv sites.csv gam user ~Owner delete drivefileacl ~id group [email protected]
    
    gam delete group [email protected]