-
-
Save irwins/e829f424facd014a86bc6a3413968492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class ADInfrastructure{ | |
[PSObject]$Forest | |
[PSObject]$Domain | |
[PSObject]$Sites | |
[PSObject]$Subnets | |
[PSObject]$Sitelinks | |
[PSObject]$DomainControllers | |
[String]$snapshotDate | |
[String]$exportFolder='C:\scripts\export\dsa' | |
[PSObject]$ADSnapshot | |
[PSObject[]]$validationResults | |
[PSObject[]]$ActionHistory | |
#Default Constructor | |
ADInfrastructure(){} | |
#Constructor | |
ADInfrastructure($frs,$dom,$sit,$sub,$stl,$dcs){ | |
$this.Forest = $frs | |
$this.Domain = $dom | |
$this.Sites = $sit | |
$this.Sitelinks = $stl | |
$this.Subnets = $sub | |
$this.DomainControllers = $dcs | |
} | |
GetCurrentConfig(){ | |
$MessageData = "Get current Active Directory configuration" | |
$this.ActionHistory += Write-Information -MessageData $MessageData 6>&1 -Tags 'Get','CurrentConfig','AD' | Select-Object * | |
$this.Forest = $(Get-ADForest) | |
$this.Domain = $(Get-ADDomain) | |
$this.DomainControllers = $(Get-ADDomainController -Filter *) | |
$this.Sites = $(Get-ADReplicationSite -Filter *) | |
$this.Subnets = $(Get-ADReplicationSubnet -Filter *) | |
$this.Sitelinks = $(Get-ADReplicationSiteLink -Filter *) | |
} | |
ImportADSnapshot(){ | |
if(Test-Path "$($this.exportFolder)\ADSnapshot-$($This.snapshotDate).xml"){ | |
$this.ADSnapshot = Import-Clixml "$($this.exportFolder)\ADSnapshot-$($This.snapshotDate).xml" | |
$MessageData = "Imported ADSnapshot from $($this.SnapshotDate)" | |
$this.ActionHistory += Write-Information -MessageData $MessageData 6>&1 -Tags 'Get','ADSnapshot','Found' | Select-Object * | |
} | |
Else{ | |
$MessageData = "ADSnapshot from $($this.SnapshotDate) not found" | |
Write-Warning -Message $MessageData | |
$this.ActionHistory += Write-Information -MessageData $MessageData 6>&1 -Tags 'Get','ADSnapshot','Missing' | Select-Object * | |
} | |
} | |
ExportADSnapshot(){ | |
$MessageData = "Saving ADSnapshot" | |
$this.ActionHistory += Write-Information -MessageData $MessageData 6>&1 -Tags 'Save','ADSnapshot' | Select-Object * | |
$exportDate = Get-Date -Format ddMMyyyy | |
$this | Export-Clixml "$($this.exportFolder)\ADSnapshot-$($exportDate).xml" -Encoding UTF8 | |
} | |
RunValidation($src,$tgt,$tag){ | |
#Something with Tags | |
$MessageData = "Validating AD Configuration against saved snapshot from $($this.SnapShotDate)" | |
$this.ActionHistory += Write-Information -MessageData $MessageData 6>&1 -Tags 'Validation','ADSnapshot','CurrentConfig','AD' | Select-Object * | |
$sbValidation = { | |
Param($Source,$Target) | |
Describe 'AD Forest configuration operational readiness' -Tags Forest { | |
Context 'Verifying Forest Configuration'{ | |
it "Forest Name $($Source.Forest.Name)" { | |
$Source.Forest.Name | | |
Should be $Target.Forest.Name | |
} | |
it "Forest Mode $($Source.Forest.ForestMode)" { | |
$Source.Forest.ForestMode | | |
Should be $Target.Forest.ForestMode | |
} | |
it "$($Source.Forest.DomainNamingMaster) is DomainNamingMaster" { | |
$Source.Forest.DomainNamingMaster| | |
Should be $Target.Forest.DomainNamingMaster | |
} | |
it "$($Source.Forest.DomainNamingMaster) is SchemaMaster"{ | |
$Source.Forest.SchemaMaster | | |
Should be $Target.Forest.SchemaMaster | |
} | |
} | |
} | |
Describe 'AD GlobalCatalog configuration operational readiness' -Tags GlobalCatalog { | |
Context 'Verifying GlobalCatalogs'{ | |
$Source.Forest.GlobalCatalogs | | |
ForEach-Object{ | |
it "Server $($_) is a GlobalCatalog"{ | |
$Target.Forest.GlobalCatalogs.Contains($_) | | |
Should be $true | |
} | |
} | |
} | |
} | |
Describe 'AD Domain configuration operational readiness' -Tags Domain{ | |
Context 'Verifying Domain Configuration'{ | |
it "Domain DN is $($Source.Domain.DistinguishedName)" { | |
$Source.Domain.DistinguishedName | | |
Should be $Target.Domain.DistinguishedName | |
} | |
it "$($Source.Domain.InfrastructureMaster) is InfrastructureMaster"{ | |
$Source.Domain.InfrastructureMaster | | |
Should be $Target.Domain.InfrastructureMaster | |
} | |
it "$($Source.Domain.PDCEmulator) is PDCEmulator"{ | |
$Source.Domain.PDCEmulator | | |
Should be $Target.Domain.PDCEmulator | |
} | |
it "$($Source.Domain.RIDMaster) is RIDMaster"{ | |
$Source.Domain.RIDMaster | | |
Should be $Target.Domain.RIDMaster | |
} | |
} | |
} | |
Describe 'AD DomainControllers configuration operational readiness' -Tags DomainControllers { | |
$lookupDC = $Target.DomainControllers | Group-Object -AsHashTable -AsString -Property Name | |
ForEach($dc in $Source.DomainControllers){ | |
Context "Verifying DC $($dc.Name) Configuration"{ | |
it "Is enabled " { | |
$dc.Enabled | Should be $lookupDC.$($dc.Name).Enabled | |
} | |
it "Is GC " { | |
$dc.IsGlobalCatalog | Should be $lookupDC.$($dc.Name).IsGlobalCatalog | |
} | |
it "ReadOnly is $($dc.IsReadOnly) " { | |
$dc.IsReadOnly| Should be $lookupDC.$($dc.Name).IsReadOnly | |
} | |
it "IPv4Address is $($dc.IPv4Address)" { | |
$dc.IPv4Address | Should be $lookupDC.$($dc.Name).IPv4Address | |
} | |
} | |
} | |
} | |
Describe 'AD Sites operational readiness' -Tags Sites { | |
Context 'Verifying Sites'{ | |
$Source.Sites | | |
ForEach-Object{ | |
it "Site $($_.Name)"{ | |
$Target.Sites.Name.Contains($_.Name) | | |
Should be $true | |
} | |
} | |
} | |
} | |
Describe 'AD Subnets operational readiness' -Tags Subnets{ | |
$lookupSubnets = $Target.SubNets | Group-Object -AsHashTable -AsString -Property Name | |
ForEach($subnet in $Source.Subnets){ | |
Context "Verifying Subnet $($subnet.Name)"{ | |
it "Subnet name is $($subnet.Name)"{ | |
$subnet.Name | Should be $lookupSubnets.$($subnet.Name).Name | |
} | |
it "Subnet location is $($subnet.Location)"{ | |
$subnet.Location | Should be $lookupSubnets.$($subnet.Name).Location | |
} | |
it "Subnet associated site is $($subnet.Site)"{ | |
$subnet.Site | Should be $lookupSubnets.$($subnet.Name).Site | |
} | |
} | |
} | |
} | |
Describe 'AD Sitelinks operational readiness' -Tags SiteLinks { | |
$lookupSiteLinks = $Target.Sitelinks | Group-Object -AsHashTable -AsString -Property Name | |
ForEach($sitelink in $Source.Sitelinks){ | |
Context "Verifying Sitelink $($sitelink.Name)"{ | |
it "Sitelink name is $($sitelink.Name)"{ | |
$sitelink.Name | Should be $lookupSiteLinks.$($sitelink.Name).Name | |
} | |
it "Sitelink cost is $($sitelink.Cost)"{ | |
$sitelink.Cost | Should be $lookupSiteLinks.$($sitelink.Name).Cost | |
} | |
it "Sitelink replication frequency (min) is $($sitelink.ReplicationFrequencyInMinutes)"{ | |
$sitelink.ReplicationFrequencyInMinutes| Should be $lookupSiteLinks.$($sitelink.Name).ReplicationFrequencyInMinutes | |
} | |
} | |
} | |
} | |
} | |
$pesterFile = "$($this.exportFolder)\ADInfra.tests.ps1" | |
$sbValidation.ToString() | out-file -FilePath $pesterFile -Force | |
$testADInfra = @( | |
@{ | |
Path = $pesterFile | |
Parameters = @{ | |
Source = $src | |
Target = $tgt | |
} | |
} | |
) | |
$this.ValidationResults += [PSCustomObject]@{ | |
ValidationDate = $(Get-Date) | |
Results = Invoke-Pester -Path $testADInfra -PassThru -Tag $tag | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment