<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Active Directory on n3s0 || notes</title>
    <link>https://notes.n3s0.tech/tags/active-directory/</link>
    <description>Recent content in Active Directory on n3s0 || notes</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Thu, 05 Aug 2021 14:14:49 -0500</lastBuildDate><atom:link href="https://notes.n3s0.tech/tags/active-directory/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Remove All AD User Group Memberships Except One Using PowerShell</title>
      <link>https://notes.n3s0.tech/posts/20210805141449/</link>
      <pubDate>Thu, 05 Aug 2021 14:14:49 -0500</pubDate>
      
      <guid>https://notes.n3s0.tech/posts/20210805141449/</guid>
      <description>Notes for a PowerShell script for removing AD user from all groups except one.</description>
      <content:encoded><![CDATA[<h2 id="overview">Overview</h2>
<p>Decided to post another fun one that I found on the Internet somewhere.
I don&rsquo;t remember the source. But, this has helped a lot. Some companies
decide to keep users around. It&rsquo;s the way it is. Managers need to see
who is or was sending them email at the time they were terminated.</p>
<p>Another reason for this to have some piece of mind. You know that should
for some reason that account gets enabled again, they wont have access
to anything that you don&rsquo;t designate.</p>
<h2 id="script">Script</h2>
<p>Going to run through what this script does quick. It&rsquo;s pretty useful when
you need to do this kind of work.</p>
<ol>
<li>Assigns the username to a variable.</li>
<li>Checks which groups the user is apart of and outputs them.</li>
<li>Effectively iterates through each group shortly after and deletes
them. With the exception of Domain Users in this case. If you would
prefer to delete group memberships from something else, go ahead.</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="nv">$Samaccountname</span> <span class="p">=</span> <span class="s2">&#34;USERNAME&#34;</span>
</span></span><span class="line"><span class="cl"><span class="p">(</span><span class="nb">Get-AdPrincipalGroupMembership</span> <span class="n">-Identity</span> <span class="nv">$Samaccountname</span><span class="p">).</span><span class="py">Samaccountname</span>
</span></span><span class="line"><span class="cl"><span class="nb">Get-AdPrincipalGroupMembership</span> <span class="n">-Identity</span> <span class="nv">$Samaccountname</span> <span class="p">|</span> <span class="nb">Where-Object</span> <span class="n">-Property</span> <span class="n">Name</span> <span class="o">-Ne</span> <span class="n">-Value</span> <span class="s1">&#39;Domain Users&#39;</span> <span class="p">|</span> <span class="nb">Remove-AdGroupMember</span> <span class="n">-Members</span> <span class="nv">$Samaccountname</span>
</span></span></code></pre></div><p>I would recommend not doing this if unnecessary. This script will remove
all group memberships from the account except for Domain Users.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
