<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vmweaver.com &#187; User Management</title>
	<atom:link href="http://vmweaver.com/index.php/tag/user-management/feed/" rel="self" type="application/rss+xml" />
	<link>http://vmweaver.com</link>
	<description>Mindless ramblings of a geek...</description>
	<lastBuildDate>Thu, 06 Oct 2011 20:42:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Powershell and Unknown User SIDs</title>
		<link>http://vmweaver.com/index.php/2009/10/powershell-and-unknown-user-sids/</link>
		<comments>http://vmweaver.com/index.php/2009/10/powershell-and-unknown-user-sids/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 18:01:19 +0000</pubDate>
		<dc:creator>Mark A. Weaver</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[AD]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[User Management]]></category>

		<guid isPermaLink="false">http://vmweaver.com/?p=204</guid>
		<description><![CDATA[Once again, my apologies for my lack of posting.. Anyway&#8230; An interesting thing came up at work the other day when one of my fellow administrators asked me if I could resolve an unknown SID he was seeing in some logs to see what the heck it belonged to. Since I had been telling him [...]]]></description>
			<content:encoded><![CDATA[<p>Once again, my apologies for my lack of posting..</p>
<p>Anyway&#8230;</p>
<p>An interesting thing came up at work the other day when one of my fellow administrators asked me if I could resolve an unknown SID he was seeing in some logs to see what the heck it belonged to.</p>
<p>Since I had been telling him that Powershell could do ANYTHING (slight exaggeration, I know)&#8230; that it should be able to do this.</p>
<p>Well, it certainly is an interesting notion.</p>
<p>I know that I have run into this in the past where you have file system ACLs set and there are a bunch of SIDs sitting in there that nobody seems to know who they belong to.</p>
<p>While it isn&#8217;t THAT important to resolve them since the user account is most likely no longer around, it IS an interesting thought exercise.</p>
<p>After perusing the web looking for others who have done something similar, I feel I had enough to throw something together..</p>
<p>Basically when an Active Directory object (like a user) is &#8220;deleted&#8221;, it is really just Tombstoned for a period of time and is moved to the hidden container &#8220;Deleted Objects&#8221; and then removed after like 90 days or so.</p>
<p>Here is my solution to &#8220;finding&#8221; those objects.</p>
<p>First you will have to know what Domain you want to look at for this object AND you have know the SID you are looking for.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Resolve<span style="color: pink;">-</span>DeletedUserSID<span style="color: #000000;">&#40;</span><span style="color: #800080;">$Domain</span><span style="color: pink;">,</span> <span style="color: #800080;">$UserSID</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;">## This is kind of a mashup of a few different scripts I found online in some forums.</span>
	<span style="color: #008000;">## Unfortunately I don't remember who did them.  If it was you, point me to your post and I will</span>
	<span style="color: #008000;">## give you the credit for your piece.</span>
	<span style="color: #008000;">## </span>
	<span style="color: #008000;">## Returns User information for deleted account with the specified SID and User Domain</span>
&nbsp;
	<span style="color: #800080;">$DomainRoot</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;LDAP://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$Domain</span>.trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$DomainDN</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>adsi<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span> <span style="color: #800080;">$DomainRoot</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.DistinguishedName
	<span style="color: #800080;">$adspath</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;LDAP://&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$DomainDN</span>
	<span style="color: #800080;">$root</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.Directoryentry<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$Adspath</span>
	<span style="color: #800080;">$root</span>.psbase.AuthenticationType <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.authenticationtypes<span style="color: #000000;">&#93;</span>::Fastbind
	<span style="color: #008000;">## We will be looking in the &quot;Deleted Objects&quot; container which is normally hidden, etc.</span>
	<span style="color: #008000;">## You will need to execute this with an account that has DomainAdmin rights to the domain you are</span>
	<span style="color: #008000;">## querying.</span>
	<span style="color: #800080;">$root</span>.psbase.path <span style="color: pink;">=</span> <span style="color: #800000;">&quot;LDAP://cn=Deleted Objects,&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$DomainDN</span>
	<span style="color: #800080;">$search</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.directorysearcher<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$root</span>
	<span style="color: #800080;">$search</span>.<span style="color: #0000FF;">filter</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;(&amp;(isDeleted=TRUE)(!(objectClass=computer))(objectclass=user))&quot;</span>
	<span style="color: #800080;">$search</span>.Tombstone <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
&nbsp;
	<span style="color: #008000;"># If you have more than 1000 users, you must NOT define SizeLimit (we haven't)</span>
	<span style="color: #008000;"># and PageSize must be less than the default value (of 1000). </span>
	<span style="color: #008000;"># I found this a bit strange...but as long as we understand it, I guess it is okay</span>
	<span style="color: #800080;">$Search</span>.PageSize <span style="color: pink;">=</span> <span style="color: #804000;">500</span>
&nbsp;
	<span style="color: #008000;"># Only look in the top level of the Deleted Objects container.</span>
	<span style="color: #800080;">$search</span>.SearchScope <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>system.directoryservices.searchscope<span style="color: #000000;">&#93;</span>::OneLevel
	<span style="color: #800080;">$result</span> <span style="color: pink;">=</span> <span style="color: #800080;">$search</span>.FindAll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># If the SID isn't found, you will get nothing returned.</span>
	<span style="color: #800080;">$result</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Name&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Name&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> `
	<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SAMAccountName&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;SAMAccountName&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> `
	<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SID&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Security.Principal.SecurityIdentifier<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;ObjectSID&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span><span style="color: pink;">,</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> `
	<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span> Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;WhenChanged&quot;</span> ; Expression <span style="color: pink;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Properties.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;WhenChanged&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span> `
	<span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">where-Object</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.SID <span style="color: #FF0000;">-ieq</span> <span style="color: #800080;">$UserSid</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As always&#8230;</p>
<p>Happy Scripting!!!! and let me know if you have questions or problems.</p>
<p>&#8211; Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://vmweaver.com/index.php/2009/10/powershell-and-unknown-user-sids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

