The works perfectly - Thanks Stephen.
The only odd thing I'm running up against is that the group of users we are 'cloning' has 83 people - under the default limit of 100 that the user search returns. However when I run my modified version of your code above along with the Copy_users function, it stops after creating the first 60 users. I thought at first this was due to some bad data or similar related to the account of the next (61st in this example) user causing the function to stop, but actually the user search is just returning 60 users.
Here's my final code using yours (slightly modified for our organization) and also a modified version of the copy_users function found in the Python API examples (https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/)
NOTE: we use Active Directory security, so this example is set up for that - our username syntax is 'ADUSERNAME@DOMAIN' - so we split the user name on the '@' sign and use the first list item from that split to feed into the IDP_USERNAME input required for AD-level security:
Copy_users function for Active Directory (I took out some name validation and user updating code as it was not needed for us - the 'adname' variable is the active directory username generated later): NOTE - the order of these items in the target_portal.users.create function DOES seem to matter. Also, obviously you need to define source_portal and target_portal using the URLS for each. Also note that here these are level 2 users, so that simplifies the function because we hard-code that value for 'level'.
Here's where I used Stephen's code to get users only in the desired group, then generate the AD Name, and call the copy_users function - after running a user search creating the 'source_users' object:
Thanks -
Allen