<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Delete a Portal User with AD-Synced Group in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-a-portal-user-with-ad-synced-group/m-p/1665569#M11781</link>
    <description>&lt;P&gt;&lt;U&gt;Environment&lt;/U&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ArcGIS Enterprise 11.4, notebook running in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;ArcGIS Notebook Standard&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;runtime.&lt;/LI&gt;&lt;LI&gt;The notebook authenticates with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;gis = GIS("home")&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(authenticating with the currently logged‑in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;built-in admin&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;account).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;U&gt;Brief Overview&lt;BR /&gt;&lt;/U&gt;&lt;/P&gt;&lt;P class=""&gt;My script processes inactive accounts and, for each user that must be removed, it:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Skips any groups whose&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;provider == "enterprise"&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(AD‑synced groups).&lt;/LI&gt;&lt;LI&gt;Removes the user from all remaining Portal‑managed groups (&lt;EM&gt;group.remove_users([user])&lt;/EM&gt;).&lt;/LI&gt;&lt;LI&gt;Re‑assigns the user’s owned content to the built-in admin&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;account (&lt;EM&gt;users.reassign_to('admin_account')&lt;/EM&gt;).&lt;/LI&gt;&lt;LI&gt;Removes the user from the Portal using the bulk-delete method (&lt;EM&gt;users.delete_users([user_to_delete])&lt;/EM&gt;)&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="python"&gt;# Remove from non‑Enterprise groups
for grp in user_to_delete.groups:
    if getattr(grp, "provider", None) != "enterprise":
        grp.remove_users([user_to_delete])

# Re‑assign owned items
user_to_delete.reassign_to('admin_account')

# Attempt delete
not_deleted = gis.users.delete_users([user_to_delete])   # returns [] on success
if not_deleted:
    print(f"Delete FAILED for: {', '.join(not_deleted)}")
else:
    print(f"User '{username}' successfully deleted.")&lt;/LI-CODE&gt;&lt;P&gt;&lt;U&gt;&lt;BR /&gt;Problem&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I then call the bulk‑delete method, it returns the username of the user I'm attempting to delete which, &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager.delete_users" target="_self"&gt;according to the docs&lt;/A&gt;, means that the delete failed.&lt;BR /&gt;&lt;BR /&gt;The Portal logs do not provide any additional insight into why the delete fails. The documentation for the &lt;EM&gt;delete_users&lt;/EM&gt; method states that "before the administrator can remove the user, all of the user’s content and groups must be reassigned or deleted". The only groups that this user is still a member of are groups where the membership is based on a SAML group which they cannot be removed from with the &lt;EM&gt;remove_users&lt;/EM&gt; method.&lt;BR /&gt;&lt;BR /&gt;&lt;U&gt;Workarounds&lt;/U&gt;&lt;BR /&gt;I can manually delete the user with the '&lt;EM&gt;Delete member'&lt;/EM&gt; option in the Members page despite their membership in these AD-synced groups but the point of this Notebook is to automate that process.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;users.delete&lt;/EM&gt; method works but seemingly requires setting the credentials explicitly (which I would rather avoid):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis = GIS("https://myportal/portal", "admin_account", "password")
user = gis.users.get(username)
user.delete()&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;U&gt;Questions&lt;/U&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Why does&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;gis.users.delete_users([user])&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;refuse to delete the account even after all non‑Enterprise groups have been cleared and content reassigned?&lt;/LI&gt;&lt;LI&gt;Is there an additional hidden prerequisite (e.g., removal from the AD identity store) that&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;delete_users&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;checks but the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;users.delete()&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;method does not?&lt;/LI&gt;&lt;LI&gt;Can&lt;SPAN&gt;&amp;nbsp;&lt;EM&gt;users.delete()&lt;/EM&gt;&amp;nbsp;&lt;/SPAN&gt;be made to work when authenticated via&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;GIS("home")&lt;/EM&gt;, or must I fall back to the explicit‑credential constructor for deletions?&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Thu, 13 Nov 2025 17:34:22 GMT</pubDate>
    <dc:creator>DavidWittmann</dc:creator>
    <dc:date>2025-11-13T17:34:22Z</dc:date>
    <item>
      <title>Delete a Portal User with AD-Synced Group</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-a-portal-user-with-ad-synced-group/m-p/1665569#M11781</link>
      <description>&lt;P&gt;&lt;U&gt;Environment&lt;/U&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ArcGIS Enterprise 11.4, notebook running in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;ArcGIS Notebook Standard&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;runtime.&lt;/LI&gt;&lt;LI&gt;The notebook authenticates with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;gis = GIS("home")&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(authenticating with the currently logged‑in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;built-in admin&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;account).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;U&gt;Brief Overview&lt;BR /&gt;&lt;/U&gt;&lt;/P&gt;&lt;P class=""&gt;My script processes inactive accounts and, for each user that must be removed, it:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Skips any groups whose&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;provider == "enterprise"&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(AD‑synced groups).&lt;/LI&gt;&lt;LI&gt;Removes the user from all remaining Portal‑managed groups (&lt;EM&gt;group.remove_users([user])&lt;/EM&gt;).&lt;/LI&gt;&lt;LI&gt;Re‑assigns the user’s owned content to the built-in admin&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;account (&lt;EM&gt;users.reassign_to('admin_account')&lt;/EM&gt;).&lt;/LI&gt;&lt;LI&gt;Removes the user from the Portal using the bulk-delete method (&lt;EM&gt;users.delete_users([user_to_delete])&lt;/EM&gt;)&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="python"&gt;# Remove from non‑Enterprise groups
for grp in user_to_delete.groups:
    if getattr(grp, "provider", None) != "enterprise":
        grp.remove_users([user_to_delete])

# Re‑assign owned items
user_to_delete.reassign_to('admin_account')

# Attempt delete
not_deleted = gis.users.delete_users([user_to_delete])   # returns [] on success
if not_deleted:
    print(f"Delete FAILED for: {', '.join(not_deleted)}")
else:
    print(f"User '{username}' successfully deleted.")&lt;/LI-CODE&gt;&lt;P&gt;&lt;U&gt;&lt;BR /&gt;Problem&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I then call the bulk‑delete method, it returns the username of the user I'm attempting to delete which, &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager.delete_users" target="_self"&gt;according to the docs&lt;/A&gt;, means that the delete failed.&lt;BR /&gt;&lt;BR /&gt;The Portal logs do not provide any additional insight into why the delete fails. The documentation for the &lt;EM&gt;delete_users&lt;/EM&gt; method states that "before the administrator can remove the user, all of the user’s content and groups must be reassigned or deleted". The only groups that this user is still a member of are groups where the membership is based on a SAML group which they cannot be removed from with the &lt;EM&gt;remove_users&lt;/EM&gt; method.&lt;BR /&gt;&lt;BR /&gt;&lt;U&gt;Workarounds&lt;/U&gt;&lt;BR /&gt;I can manually delete the user with the '&lt;EM&gt;Delete member'&lt;/EM&gt; option in the Members page despite their membership in these AD-synced groups but the point of this Notebook is to automate that process.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;users.delete&lt;/EM&gt; method works but seemingly requires setting the credentials explicitly (which I would rather avoid):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis = GIS("https://myportal/portal", "admin_account", "password")
user = gis.users.get(username)
user.delete()&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;U&gt;Questions&lt;/U&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Why does&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;gis.users.delete_users([user])&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;refuse to delete the account even after all non‑Enterprise groups have been cleared and content reassigned?&lt;/LI&gt;&lt;LI&gt;Is there an additional hidden prerequisite (e.g., removal from the AD identity store) that&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;delete_users&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;checks but the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;users.delete()&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;method does not?&lt;/LI&gt;&lt;LI&gt;Can&lt;SPAN&gt;&amp;nbsp;&lt;EM&gt;users.delete()&lt;/EM&gt;&amp;nbsp;&lt;/SPAN&gt;be made to work when authenticated via&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;GIS("home")&lt;/EM&gt;, or must I fall back to the explicit‑credential constructor for deletions?&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 13 Nov 2025 17:34:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-a-portal-user-with-ad-synced-group/m-p/1665569#M11781</guid>
      <dc:creator>DavidWittmann</dc:creator>
      <dc:date>2025-11-13T17:34:22Z</dc:date>
    </item>
  </channel>
</rss>

