<?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>get-adobject &#8211; Carl Webster</title>
	<atom:link href="https://www.carlwebster.com/tag/get-adobject/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.carlwebster.com</link>
	<description>The Accidental Citrix Admin - The site for those who find themselves supporting Citrix involuntarily or accidentally</description>
	<lastBuildDate>Mon, 21 Apr 2014 13:06:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">42228915</site>	<item>
		<title>Finding Domain Trusts in an Active Directory Forest using Microsoft PowerShell</title>
		<link>https://www.carlwebster.com/finding-domain-trusts-active-directory-forest-using-microsoft-powershell/</link>
					<comments>https://www.carlwebster.com/finding-domain-trusts-active-directory-forest-using-microsoft-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Carl Webster]]></dc:creator>
		<pubDate>Mon, 21 Apr 2014 13:06:56 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[get-adforest]]></category>
		<category><![CDATA[get-adobject]]></category>
		<category><![CDATA[powershell domain trusts]]></category>
		<category><![CDATA[powershell forest trusts]]></category>
		<guid isPermaLink="false">https://www.carlwebster.com/?p=7066</guid>

					<description><![CDATA[For my Active Directory (AD) documentation script, I needed to enumerate all Trusts for a Domain. I found a script on TechNet but it had issues. I fixed the issues&#8230;]]></description>
										<content:encoded><![CDATA[<p>For my Active Directory (AD) documentation script, I needed to enumerate all Trusts for a Domain. I found a script on TechNet but it had issues. I fixed the issues but I cannot post it as a solution on TechNet because my script is longer than 2000 characters.<br />
<span id="more-7066"></span><br />
I found the original script <a title="Enumerate Domain Trusts with Extended Information" href="http://gallery.technet.microsoft.com/scriptcenter/Enumerate-Domain-Trusts-25ecb802" target="_blank">here</a>.</p>
<p>My issues with the original script are:</p>
<ul>
<li>No error checking</li>
<li> Did not handle singletons</li>
<li> Did not use its $DomainDNS variable in the Get-ADObject call to specify which domain to restrict the trusts</li>
<li> The $TrustAttributesNumber variable used decimal values instead of hexadecimal values (i.e. 20 instead of 32)</li>
<li> The $TrustAttributesNumber variable did not have a value for Inter-Forest trusts (hex 64)</li>
<li> The Switch statements did not use Default but used an If statement after the Switch statement to set the Default value</li>
</ul>
<p>Here is my version of the script.</p>
<pre class="brush: powershell; title: ; notranslate">
#http://gallery.technet.microsoft.com/scriptcenter/Enumerate-Domain-Trusts-25ecb802#content
Import-module ActiveDirectory
$Domains = (Get-ADForest).Domains

If($? -and $Domains -ne $Null)
{
	ForEach($Domain in $Domains)
	{ 
		Write-output &quot;Get list of AD Domain Trusts in $Domain `r&quot;; 
		$ADDomainTrusts = Get-ADObject -Filter {ObjectClass -eq &quot;trustedDomain&quot;} -Server $Domain -Properties * -EA 0

		If($? -and $ADDomainTrusts -ne $Null)
		{
			If($ADDomainTrusts -is &#x5B;array])
			{
				&#x5B;int]$ADDomainTrustsCount = $ADDomainTrusts.Count 
			}
			Else
			{
				&#x5B;int]$ADDomainTrustsCount = 1
			}
			
			Write-Output &quot;Discovered $ADDomainTrustsCount trusts in $Domain&quot; 
			
			ForEach($Trust in $ADDomainTrusts) 
			{ 
				$TrustName = $Trust.Name 
				$TrustDescription = $Trust.Description 
				$TrustCreated = $Trust.Created 
				$TrustModified = $Trust.Modified 
				$TrustDirectionNumber = $Trust.TrustDirection
				$TrustTypeNumber = $Trust.TrustType
				$TrustAttributesNumber = $Trust.TrustAttributes

				#http://msdn.microsoft.com/en-us/library/cc220955.aspx
				#no values are defined at the above link
				Switch ($TrustTypeNumber) 
				{ 
					1 { $TrustType = &quot;Downlevel (Windows NT domain external)&quot;} 
					2 { $TrustType = &quot;Uplevel (Active Directory domain - parent-child, root domain, shortcut, external, or forest)&quot;} 
					3 { $TrustType = &quot;MIT (non-Windows) Kerberos version 5 realm&quot;} 
					4 { $TrustType = &quot;DCE (Theoretical trust type - DCE refers to Open Group's Distributed Computing Environment specification)&quot;} 
					Default { $TrustType = $TrustTypeNumber }
				} 

				#http://msdn.microsoft.com/en-us/library/cc223779.aspx
				Switch ($TrustAttributesNumber) 
				{ 
					1 { $TrustAttributes = &quot;Non-Transitive&quot;} 
					2 { $TrustAttributes = &quot;Uplevel clients only (Windows 2000 or newer&quot;} 
					4 { $TrustAttributes = &quot;Quarantined Domain (External)&quot;} 
					8 { $TrustAttributes = &quot;Forest Trust&quot;} 
					16 { $TrustAttributes = &quot;Cross-Organizational Trust (Selective Authentication)&quot;} 
					32 { $TrustAttributes = &quot;Intra-Forest Trust (trust within the forest)&quot;} 
					64 { $TrustAttributes = &quot;Inter-Forest Trust (trust with another forest)&quot;} 
					Default { $TrustAttributes = $TrustAttributesNumber }
				} 
				 
				#http://msdn.microsoft.com/en-us/library/cc223768.aspx
				Switch ($TrustDirectionNumber) 
				{ 
					0 { $TrustDirection = &quot;Disabled (The trust relationship exists but has been disabled)&quot;} 
					1 { $TrustDirection = &quot;Inbound (TrustING domain)&quot;} 
					2 { $TrustDirection = &quot;Outbound (TrustED domain)&quot;} 
					3 { $TrustDirection = &quot;Bidirectional (two-way trust)&quot;} 
					Default { $TrustDirection = $TrustDirectionNumber }
				}
					   
				Write-output &quot;`tTrust Name: $TrustName `r &quot; 
				Write-output &quot;`tTrust Description: $TrustDescription `r &quot; 
				Write-output &quot;`tTrust Created: $TrustCreated `r &quot; 
				Write-output &quot;`tTrust Modified: $TrustModified  `r &quot; 
				Write-output &quot;`tTrust Direction: $TrustDirection `r &quot; 
				Write-output &quot;`tTrust Type: $TrustType `r &quot; 
				Write-output &quot;`tTrust Attributes: $TrustAttributes `r &quot; 
				Write-output &quot; `r &quot; 
			}
		}
		ElseIf(!$?)
		{
			#error retrieving domain trusts
			Write-output &quot;Error retrieving domain trusts for $Domain&quot;
		}
		Else
		{
			#no domain trust data
			Write-output &quot;No domain trust data for $Domain&quot;
		}
	} 
}
ElseIf(!$?)
{
	#error retrieving domains
	Write-output &quot;Error retrieving domains&quot;
}
Else
{
	#no domain data
	Write-output &quot;No domain data&quot;
}
</pre>
<p>The original script only processed the domain in which the user was running the script. I changed it to process all domains in the forest.</p>
<p>I am using Write-Output as that is what the original script uses. I will update this code to work in my script using my normal output routines.</p>
<p>Thanks</p>
<p>Webster</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.carlwebster.com/finding-domain-trusts-active-directory-forest-using-microsoft-powershell/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7066</post-id>	</item>
	</channel>
</rss>
