Active Directory configuration snapshot

‘Sup PSHomies,

Back in the days I had some vbs scripts to make a quick assessment of whatever  Active Directory I was working on. Guess it’s time to upgrade to PowerShell! 😉

Ever since I read the book on Big Data: A Revolution That Will Transform How We Live, Work, and Think, I’ve started looking at my datasets differently. When gathering data, we usually assume that our dataset has a singular purpose to which its value is tied.

By not being overly occupied with filtering the dataset we can always revisit and probably gain more insight we hadn’t thought of at the time. (I’ll demonstrate later on). Let’s dive in!


<#
Author: I. Strachan
Version:
Version History:
Purpose: Get ADConfiguration for current Domain
#>
[cmdletbinding()]
Param()
Import-Module ActiveDirectory Verbose:$false
#HashTable to save ADReport
$ADSnapshot = @{}
#region Main
$ADSnapshot.RootDSE = $(Get-ADRootDSE)
$ADSnapshot.ForestInformation = $(Get-ADForest)
$ADSnapshot.DomainInformation = $(Get-ADDomain)
$ADSnapshot.DomainControllers = $(Get-ADDomainController Filter *)
$ADSnapshot.DomainTrusts = (Get-ADTrust Filter *)
$ADSnapshot.DefaultPassWordPoLicy = $(Get-ADDefaultDomainPasswordPolicy)
$ADSnapshot.AuthenticationPolicies = $(Get-ADAuthenticationPolicy LDAPFilter '(name=AuthenticationPolicy*)')
$ADSnapshot.AuthenticationPolicySilos = $(Get-ADAuthenticationPolicySilo Filter 'Name -like "*AuthenticationPolicySilo*"')
$ADSnapshot.CentralAccessPolicies = $(Get-ADCentralAccessPolicy Filter *)
$ADSnapshot.CentralAccessRules = $(Get-ADCentralAccessRule Filter *)
$ADSnapshot.ClaimTransformPolicies = $(Get-ADClaimTransformPolicy Filter *)
$ADSnapshot.ClaimTypes = $(Get-ADClaimType Filter *)
$ADSnapshot.DomainAdministrators =$( Get-ADGroup Identity $('{0}-512' -f (Get-ADDomain).domainSID) | Get-ADGroupMember Recursive)
$ADSnapshot.OrganizationalUnits = $(Get-ADOrganizationalUnit Filter *)
$ADSnapshot.OptionalFeatures = $(Get-ADOptionalFeature Filter *)
$ADSnapshot.Sites = $(Get-ADReplicationSite Filter *)
$ADSnapshot.Subnets = $(Get-ADReplicationSubnet Filter *)
$ADSnapshot.SiteLinks = $(Get-ADReplicationSiteLink Filter *)
$ADSnapshot.ReplicationMetaData = $(Get-ADReplicationPartnerMetadata Target (Get-ADDomain).DNSRoot Scope Domain)
#endregion
#region Export to XML
$exportDate = Get-Date Format ddMMyyyy
$ADSnapshot | Export-Clixml .\export\dsa\ADReport$($exportDate).xml Encoding UTF8
#endregion
#region AD Queries
$ADSnapshot.DomainControllers | Format-Table Name,OperatingSystem,IPv4Address,Site
$ADSnapshot.DomainAdministrators | Format-Table Name
$ADSnapshot.ForestInformation.GlobalCatalogs
$ADSnapshot.ForestInformation | Format-Table SchemaMaster,DomainNamingMaster
$ADSnapshot.DomainInformation | Format-Table PDCEmulator,RIDMaster,InfrastructureMaster
$ADSnapshot.OrganizationalUnits | Format-Table Name,DistinguishedName
$ADSnapshot.Sites | Format-Table Name
$ADSnapshot.Subnets | Format-Table Name
$ADSnapshot.SiteLinks | Format-Table Name,Cost,ReplicationFrequencyInMinutes
#endregion
#region Compare Objects
#Get previous ADReport
$SavedADSnapshot = Import-Clixml .\export\dsa\ADReport22032016.xml
#Compare Forest FSMO roles
Compare-Object $SavedADSnapshot.ForestInformation $ADSnapshot.ForestInformation Property SchemaMaster,DomainNamingMaster IncludeEqual
#Compare Domain FSMO roles
Compare-Object $SavedADSnapshot.DomainInformation $ADSnapshot.DomainInformation Property PDCEmulator,RIDMaster,InfrastructureMaster IncludeEqual
#endregion

I’ve create a hashtable to save all necessary bits for further processing. Noticed I didn’t filter just gathered all possible information (-Filter *)

Quick side step: I’ve exported the Object using Export-Clixml for future use, to be continued… 😉

The fun really begins when we run queries against $ADSnapshot

Let’s take $ADSnapshot.DomainControllers as an example

How many DomainControllers are there?

@($ADSnapshot.DomainControllers).Count

What are their names?

$ADSnapshot.DomainControllers | Format-Table Name,

Here’s where the added value comes in. If we had opted for a singular purpose dataset then that would have been all the data we could have extracted. Suppose I want to know which site the Domain Controller resides in?

$ADSnapshot.DomainControllers | Format-Table Name,Site

But there’s even more data you could extract. Have a look at the properties available:

$ADReport.DomainControllers | Get-Member -MemberType Property

Need the Partitions?

$ADReport.DomainControllers.Partitions

How about the ports available?

$ADSnapshot.DomainControllers | Format-Table *Port

I think you get the idea… 😉

There’s even an added bonus I hadn’t thought of… remember the export using Export-Clixml? Well we can use that to compare previous Snapshots

Did the FSMO Roles Change since last snapshot?

Compare-Object $SavedADSnapshot.DomainInformation $ADSnapshot.DomainInformation -Property PDCEmulator,RIDMaster,InfrastructureMaster -IncludeEqual

So there you have it, Active Directory configuration snapshot! By gathering all possible information first and processing later on, we can uncover additional information if needed… I’ve been in a situation where I had a limited window to gather Active Directory information… The pressure! If I missed any bit, then that was it, I didn’t get a second chance! Now I can gather all possible information and revisit the dataset on the off-chance I missed something the first time…

Next time I’ll show you how to create a HTML report using the saved $ADReport… 😉

Hope it’s worth something to you.

Ttyl,

Urv

Advertisement

6 thoughts on “Active Directory configuration snapshot

  1. Pingback: Active Directory configuration report | pshirwin

  2. Pingback: Active Directory Operations Test | pshirwin

  3. Pingback: PScribo for the win! | pshirwin

  4. Pingback: Powershell Reporting using Pscribo Part 1 -Getting the XML | Wei-Yen Tan’s IT Journal

  5. Pingback: AD Operation Validation class | pshirwin

  6. Great Gentle Man

    Hi thanks for the article. just the thing i was looking for.
    similarly need to export Ms Exchange 2013 configurations. can you help me in that.

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s