How to transfer a folder to a different user in google Drive

Background

There was an accidental user deletion and a users entire google drive was transferred to a different user. Unfortunately to my current understanding other than this method the only other way of transferring the folder and ownership is by manually selecting each file and sub folder and sharing, then transferring the ownership, which is both time consuming and requires intervention with the end user, neither of which is a good look. This can probably be done a bit more efficiently but it got the job done for me. Also may not work in all environments as there has been talks of ownership changes requiring the new owner to accept the transfer but I did not experience this issue but use with caution and please test first.

Prerequisites

This is for Google Workspace not personal google accounts
This is for Google Workspace Admins
This is for Users MyDrive not shared Drive
Working installation of GAM7 (Ubuntu)

Commands Used

//command returns the ID for everything in MyDrive *(If too large may want to add todrive tdtitle "AllFolders_Sheet")
gam user sourceUser@domain.com print filelist showmimetype gfolder excludetrashed fields name, id

//Enter the id of the folder you are searching to transfer
gam user sourceUser@domain.com print filelist select ID <Folders_ID> showownedby me fields id todrive tdtitle "FolderList_Sheet"

//command uses the csv generated to change the owner of every item in the folder
gam csv gsheet admin@domain.com "FolderList_Sheet" gam user ~Owner add drivefileacl ~id user targetUser@domain.com role owner

//command changes the ownership of the folder itself
gam user targetUser@domain.com add drivefileacl <Folders_ID> user targetUser@domain.com role owner

//command moves the folder to the root of the new owners myDrive
gam user targetUser@domain.com update drivefile id <Folders_ID> addparent root

//command gets the id of all permissions on the folder
gam user targetUser@domain.com show drivefileacl <Folders_ID>

//command removes the previous owner from the permissions completely
gam user targetUser@domain.com delete drivefileacl <sourceUsers_ID>