Skip to content

Commit 6e8ae45

Browse files
committed
Add functions
1 parent 34a2c10 commit 6e8ae45

File tree

8 files changed

+193
-0
lines changed

8 files changed

+193
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#WIP
2+
3+
# Get all DC records and test them for connectivity
4+
Get-ADDomainController -Filter * | Sort-Object Name | Format-Table Name, Enabled, IsGlobalCatalog, ComputerObjectDN
5+
foreach ($dc in $dcs) {
6+
Test-NetConnection $dc.DnsHostname | Select-Object ComputerName, RemoteAddress, PingSucceeded | Format-Table
7+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Get-ADForestDomainControllerBackups {
2+
<#
3+
.SYNOPSIS
4+
Get the last backup date of Active Directory domain controllers in the forest.
5+
6+
.DESCRIPTION
7+
Get-ADForestDomainControllerBackups retrieves the last successful backup date of each domain controller in the forest.
8+
9+
.EXAMPLE
10+
Get-ADForestDomainControllerBackups
11+
Get the last backup date of all domain controllers in the forest.
12+
13+
.NOTES
14+
Author: Sam Erde, Sentinel Technologies, Inc.
15+
Version: 0.0.1
16+
Modified: 2024-11-18
17+
#>
18+
[CmdletBinding()]
19+
param ()
20+
21+
begin {
22+
$ForestDomainControllers = foreach ($domain in (Get-ADForest).domains) {
23+
Get-ADDomainController -Server $domain -Filter *
24+
}
25+
}
26+
process {
27+
foreach ($DC in $ForestDomainControllers) {
28+
$DCName = Get-ADObject -Identity $DC.NTDSSettingsObjectDN -Properties *
29+
$BackupTime = Get-ADObject -Identity $DCName -Properties BackupLastSuccessful
30+
if ($backupTime.BackupLastSuccessful) {
31+
"Last backup time for $($DC.Name): $($backupTime.BackupLastSuccessful)"
32+
} else {
33+
'No backup information available.'
34+
}
35+
#[PSCustomObject]@{
36+
# Hostname = $DC.HostName
37+
# LastBackupDate = $BackupDate
38+
#}
39+
}
40+
}
41+
end {}
42+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Import-Module ActiveDirectory
2+
$sites = Get-ADReplicationSite -Filter *
3+
foreach ($site in $sites) {
4+
$siteLinks = Get-ADReplicationSiteLink -Filter { SitesIncluded -match $($site.Name) }
5+
[PSCustomObject]@{
6+
SiteName = $site.Name
7+
SiteLinks = $siteLinks.Name -join ', '
8+
}
9+
}
10+
Get-ADReplicationSiteLink -Filter 'SitesIncluded -contains "Default-First-Site-Name"' | Select-Object -ExpandProperty Name
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function Get-ADSitesWithoutLinks {
2+
<#
3+
.SYNOPSIS
4+
Get all Active Directory sites that are not included in any site link.
5+
6+
.DESCRIPTION
7+
Get-ADSitesWithoutLinks gets all Active Directory replication sites and site links, and then determines which sites are not included in any site link.
8+
9+
.EXAMPLE
10+
Get-ADSitesWithoutLinks
11+
12+
.EXAMPLE
13+
Get-AdSitesWithoutLinks | Format-Table @{Name = 'Site'; Expression = { $_.Key } }, @{Name = 'SiteLink[s]'; Expression = { $_.Value -join ', '}}
14+
15+
Format the output as a table with custom headers.
16+
17+
.NOTES
18+
Author: Sam Erde, Sentinel Technologies, Inc.
19+
Version: 0.0.1
20+
Modified: 2024-11-18
21+
#>
22+
[CmdletBinding()]
23+
param ( )
24+
25+
begin { }
26+
27+
process {
28+
# Create an ordered dictionary hash table from $ADSites that stores the site name as the key and the site object as the value.
29+
$ADSites = [ordered]@{}
30+
foreach ($site in (Get-ADReplicationSite -Filter * -Properties * -ErrorAction SilentlyContinue | Sort-Object -Property Name)) {
31+
$ADSites[$site.Name] = $site
32+
}
33+
34+
$ADSiteLinks = Get-ADReplicationSiteLink -Filter * | Sort-Object -Property Name
35+
36+
$SiteLinkMap = [ordered]@{}
37+
foreach ( $siteName in ($ADSites.GetEnumerator()).Name ) {
38+
39+
foreach ($link in $ADSiteLinks) {
40+
foreach ($siteIncluded in $link.SitesIncluded) {
41+
if ( (Get-ADReplicationSite $siteIncluded).Name -eq $siteName ) {
42+
$SiteLinkMap[$SiteName] += "$($link).Name, " # need to remove the last comma and space from the last item
43+
}
44+
}
45+
}
46+
}
47+
48+
foreach ($siteLink in $SiteLinkMap.GetEnumerator()) {
49+
if ($null -eq $siteLink.Value) {
50+
Write-Warning -Message "The site $($siteLink.Key) is not found in any site link."
51+
}
52+
}
53+
#endregion Sites without SiteLinks
54+
}
55+
56+
end {
57+
$SiteLinkMap
58+
}
59+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# WIP
2+
3+
# Check domain controllers' time sources.
4+
$DomainControllers = Get-ADDomainController -Filter *
5+
foreach ($DC in $DomainControllers) {
6+
$TimeSource = w32tm /query /status /computer:$DC.HostName | Select-String 'Source'
7+
[PSCustomObject]@{
8+
Hostname = $DC.HostName
9+
TimeSource = $TimeSource -replace 'Source: ', ''
10+
}
11+
}
12+
13+
# Check the time settings on each domain controller using Get-CimInstance
14+
foreach ($DC in $DomainControllers) {
15+
$TimeSettings = Get-CimInstance -ClassName Win32_TimeZone -ComputerName $DC.HostName
16+
[PSCustomObject]@{
17+
Hostname = $DC.HostName
18+
Caption = $TimeSettings.Caption
19+
Description = $TimeSettings.Description
20+
StandardName = $TimeSettings.StandardName
21+
DaylightName = $TimeSettings.DaylightName
22+
}
23+
}
24+
25+
# Check the NTP server and Win32Time service status on each domain controller using Get-CimInstance
26+
foreach ($DC in $DomainControllers) {
27+
$NTPServer = Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $DC.HostName | Select-Object -ExpandProperty DomainRole
28+
$Win32TimeService = Get-CimInstance -ClassName Win32_Service -Filter "Name='w32time'" -ComputerName $DC.HostName
29+
30+
[PSCustomObject]@{
31+
Hostname = $DC.HostName
32+
NTPServer = $NTPServer
33+
Win32TimeServiceState = $Win32TimeService.State
34+
Win32TimeServiceStartMode = $Win32TimeService.StartMode
35+
}
36+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# WIP
2+
3+
# Check the last backup date of Active Directory domain controllers
4+
foreach ($DC in $ForestDomainControllers) {
5+
$BackupDate = Get-ADObject -Filter { ObjectClass -eq 'msDS-LastSuccessfulBackup' } -SearchBase "CN=NTDS Settings,CN=$($DC.Name),CN=Servers,CN=$($DC.Site),CN=Sites,CN=Configuration,$((Get-ADRootDSE).ConfigurationNamingContext)" -Property msDS-LastSuccessfulBackup | Select-Object -ExpandProperty msDS-LastSuccessfulBackup
6+
7+
[PSCustomObject]@{
8+
Hostname = $DC.HostName
9+
LastBackupDate = $BackupDate
10+
}
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#WIP
2+
3+
# Get the hostname and AD site location of domain controllers that hold the AD FSMO roles.
4+
$FSMORoles = Get-ADForest | Select-Object -ExpandProperty SchemaMaster, DomainNamingMaster
5+
$FSMORoles += Get-ADDomain | Select-Object -ExpandProperty PDCEmulator, RIDMaster, InfrastructureMaster
6+
7+
# Get the details of each FSMO role holder
8+
foreach ($role in $FSMORoles) {
9+
$DC = Get-ADDomainController -Identity $role
10+
[PSCustomObject]@{
11+
Hostname = $DC.HostName
12+
IPAddress = $DC.IPAddress
13+
ADSite = $DC.Site
14+
}
15+
}

DDI/Get-ServiceRecords.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# WIP
2+
3+
# Get all DNS zones
4+
$zones = Get-DnsServerZone -ComputerName (Get-Domain) | Where-Object { $_.ZoneType -eq 'Primary' }
5+
6+
# Loop through each zone and get SRV records
7+
foreach ($zone in $zones) {
8+
$srvRecords = Get-DnsServerResourceRecord -ZoneName $zone.ZoneName -RRType SRV | Where-Object { $_.HostName -notmatch 'ldap' -and $_.HostName -notmatch 'gc' -and $_.HostName -notmatch 'kerberos' }
9+
foreach ($record in $srvRecords) {
10+
Write-Host "Name: $($record.HostName), Target: $($record.RecordData.Target), Port: $($record.RecordData.Port), Priority: $($record.RecordData.Priority), Weight: $($record.RecordData.Weight)"
11+
Write-Host "$zone"
12+
}
13+
}

0 commit comments

Comments
 (0)