Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
d7d2e66
Add files via upload
Hal-Scriptville Mar 20, 2024
2b686bb
Add files via upload
Hal-Scriptville Mar 21, 2024
120ec66
Add files via upload
Hal-Scriptville Mar 22, 2024
19a3a7b
Add files via upload
Hal-Scriptville Mar 22, 2024
59e6a84
Add files via upload
Hal-Scriptville Apr 3, 2024
b26b0d4
Rename Get-DomainComputerTimestamps.ps1 to Get-InstalledSoftware.ps1
Hal-Scriptville Apr 3, 2024
6094c42
Rename Get-UninstallStrings.ps1 to Get-ComputerTimestamps.ps1
Hal-Scriptville Apr 3, 2024
0fcdf16
Add files via upload
Hal-Scriptville Apr 5, 2024
943b60e
Add files via upload
Hal-Scriptville Apr 5, 2024
d2cbdd6
Add files via upload
Hal-Scriptville Apr 26, 2024
06a8aca
Update Check-ADHealth.ps1
Hal-Scriptville May 15, 2024
f19bad5
Update Check-ADHealth.ps1
Hal-Scriptville May 15, 2024
be02229
Create Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
90ae95c
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
c3f47cc
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
3e16fa9
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
d493345
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
c39b869
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
480793d
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
f391627
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 15, 2024
a9e84a1
Update Check-ADHealth_NEW.ps1
Hal-Scriptville May 16, 2024
95238e1
Add files via upload
Hal-Scriptville Jul 19, 2024
6ac286b
Add files via upload
Hal-Scriptville Jul 29, 2024
0e361a0
Add files via upload
Hal-Scriptville Jul 30, 2024
4387919
Add files via upload
Hal-Scriptville Aug 1, 2024
228c344
Update Detect-IntuneCache.ps1
Hal-Scriptville Aug 1, 2024
4b60a58
Update Detect-IntuneCache.ps1
Hal-Scriptville Aug 1, 2024
a9106b4
Add files via upload
Hal-Scriptville Aug 1, 2024
68405ed
Add files via upload
Hal-Scriptville Aug 1, 2024
001015b
Add files via upload
Hal-Scriptville Aug 9, 2024
916fc27
Add files via upload
Hal-Scriptville Sep 18, 2024
6ad30bd
Add files via upload
Hal-Scriptville Sep 18, 2024
0660d96
Add files via upload
Hal-Scriptville Sep 19, 2024
1931743
Update Detect-WingetUpdates.ps1
Hal-Scriptville Oct 16, 2024
b16183f
Update Remediate-WingetUpdates.ps1
Hal-Scriptville Oct 16, 2024
5a82a58
Add files via upload
Hal-Scriptville Oct 16, 2024
f5b9964
Add files via upload
Hal-Scriptville Nov 4, 2024
dd63275
Add files via upload
Hal-Scriptville Nov 4, 2024
3cf243e
Create Remediate-WiredAutoConfig.ps1
Hal-Scriptville Nov 14, 2024
af5afeb
Create Detect-WiredAutoConfig.ps1
Hal-Scriptville Nov 14, 2024
94bc2fb
Create Detect-WUServer.ps1
Hal-Scriptville Nov 19, 2024
97bfe83
Create Remediate-WUServer.ps1
Hal-Scriptville Nov 19, 2024
47b0163
Add files via upload
Hal-Scriptville Nov 21, 2024
886d973
Add files via upload
Hal-Scriptville Nov 25, 2024
d1a5d01
Create Detect-FixedDrive.ps1
Hal-Scriptville Dec 2, 2024
e87c441
Detect-FixedDrive.ps1
Hal-Scriptville Dec 5, 2024
858ff4e
Check-ADHealth_NEW.ps1
Hal-Scriptville Dec 17, 2024
1499fb1
Create Backup-Permissions
Hal-Scriptville Dec 31, 2024
cfeba22
Create Change-Ownership.ps1
Hal-Scriptville Dec 31, 2024
54aeba1
Delete Backup-Permissions
Hal-Scriptville Dec 31, 2024
1e6d5d2
Backup-Permissions.ps1
Hal-Scriptville Dec 31, 2024
1f590d5
Check-ADHealth.ps1
Hal-Scriptville Jan 21, 2025
d2583d5
Add files via upload
Hal-Scriptville Jan 23, 2025
08dee6f
Add files via upload
Hal-Scriptville Feb 3, 2025
2a7b78f
Remediate-CarbonBlack.ps1
Hal-Scriptville Feb 3, 2025
51e0380
Discover-Printers_CIM_WMI.ps1
Hal-Scriptville Feb 5, 2025
52c5039
Discover-Printer_PS.ps1
Hal-Scriptville Feb 5, 2025
fe8ceff
Rename Discover-Printer_PS.ps1 to Discover-Printers_PS.ps1
Hal-Scriptville Feb 5, 2025
fc6ae15
Add files via upload
Hal-Scriptville Feb 6, 2025
0492bc3
Create Exchange-MailboxRetentionPolicyManager.ps1
Hal-Scriptville Feb 26, 2025
25218f9
Create Clean-IntuneEnrollment.ps1
Hal-Scriptville Mar 10, 2025
3943771
Create Set-EnrollmentAttribute.ps1
Hal-Scriptville Mar 11, 2025
70bdebe
Create Set-EnrollmentAttribute_RANGE.ps1
Hal-Scriptville Mar 11, 2025
926c2f4
Create Check-ADHealth_Updated.ps1
Hal-Scriptville Apr 11, 2025
39d12f1
Add files via upload
Hal-Scriptville Jun 25, 2025
e862caa
Build-IntuneAppBuilder.ps1
Hal-Scriptville Jun 25, 2025
2cc20c3
Build-IntuneAppBuilder.ps1
Hal-Scriptville Jun 25, 2025
8ea8971
Add files via upload
Hal-Scriptville Aug 1, 2025
8b40f1d
Detect-WUEntries.ps1
Hal-Scriptville Aug 11, 2025
ff43a63
Remediate-WUEntries.ps1
Hal-Scriptville Aug 11, 2025
797953f
Detect-WUEntries.ps1
Hal-Scriptville Aug 11, 2025
3e92f33
Remediate-WUEntries.ps1
Hal-Scriptville Aug 12, 2025
60c139e
Add files via upload
Hal-Scriptville Aug 19, 2025
5619545
Remediate-IntuneUpdateSettings.ps1
Hal-Scriptville Aug 19, 2025
8b17e7c
Detect-IntuneUpdateSettings.ps1
Hal-Scriptville Aug 19, 2025
8fc5b16
Add files via upload
Hal-Scriptville Aug 20, 2025
4cea802
Detect-IntuneCoManageSettings.ps1
Hal-Scriptville Aug 20, 2025
8f11313
Detect-IntuneCoManageSettings.ps1
Hal-Scriptville Aug 20, 2025
6724885
Remediate-IntuneCoManageSettings.ps1
Hal-Scriptville Aug 20, 2025
eb4b3e7
Remediate-IntuneCoManageSettings.ps1
Hal-Scriptville Aug 20, 2025
64d3041
Remediate-IntuneCoManageSettings.ps1
Hal-Scriptville Aug 20, 2025
52c37c7
Remediate-IntuneCoManageSettings.ps1
Hal-Scriptville Aug 20, 2025
ff0cb3b
Create-StaleDeviceGroup.ps1
Hal-Scriptville Aug 25, 2025
3c97724
Delete-StaleDeviceByGroup.ps1
Hal-Scriptville Aug 25, 2025
133dac4
Sysprep-PreCleanup.ps1
Hal-Scriptville Aug 28, 2025
a6d8dff
Cleanup-Apps4Sysprep.ps1
Hal-Scriptville Aug 29, 2025
c2faafb
Rename Cleanup-Apps4Sysprep.ps1 to Enhanced-AppX-Cleanup.ps1
Hal-Scriptville Aug 29, 2025
08d25c7
Create Nuclear-Appx-Cleanup.ps1
Hal-Scriptville Aug 29, 2025
e8cb8cf
Create WindowsUpdate-Reset.ps1
Hal-Scriptville Oct 2, 2025
7b20713
Create Find-MissingKeyInBitlocker.ps1
Hal-Scriptville Oct 10, 2025
ac6d627
Create Sync-OUToSecurityGroups-Scheduled.ps1
Hal-Scriptville Nov 1, 2025
3cdf437
Create Intune-AutoEnrollment-HybridJoined.ps1
Hal-Scriptville Dec 12, 2025
bb41a4f
Create Add-ADFSDeviceClaimRules.ps1
Hal-Scriptville Dec 18, 2025
4ca393c
Update Add-ADFSDeviceClaimRules.ps1
Hal-Scriptville Dec 18, 2025
45ec659
Update Get-GPOReports.ps1
Hal-Scriptville Jan 13, 2026
f57d2e0
Create Detect-MdmEnrollmentBlock.ps1
Hal-Scriptville Jan 22, 2026
e79a7dc
Create Remediate-MdmEnrollmentBlock.ps1
Hal-Scriptville Jan 22, 2026
3eece53
Add GroupPolicyAnalyticsCleanup.js from archived NodeJS repo
Hal-Scriptville Mar 27, 2026
758a692
Add intune_enrollment.bat from archived OtherScripts repo
Hal-Scriptville Mar 27, 2026
18569d8
Reorganize scripts into folder structure
Hal-Scriptville Mar 27, 2026
9fdd644
Improve SCCM client agent detection and remediation scripts
Hal-Scriptville Apr 2, 2026
a4d2769
Rewrite Build-IntuneAppBuilder as parameterized packager
Hal-Scriptville Apr 14, 2026
4a35913
Use Chrome as the public reference example (replaces NinjaOne)
Hal-Scriptville Apr 14, 2026
3e600e4
Add -ToolPath param to reuse a shared IntuneWinAppUtil.exe
Hal-Scriptville Apr 14, 2026
7037525
Add New-IntuneApp.ps1 — lightweight scaffold for the shared-root layout
Hal-Scriptville Apr 14, 2026
151417c
Add version header and changelog (v3.0)
Hal-Scriptville Apr 14, 2026
a0a3d63
Add Build-TokenizedAgentPackages.ps1 — bulk builder from CSV
Hal-Scriptville Apr 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 219 additions & 0 deletions AD/Add-ADFSDeviceClaimRules.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<#
.SYNOPSIS
Adds device authentication claim rules to ADFS for hybrid Azure AD join with MDM auto-enrollment.

.DESCRIPTION
This script adds the required device claim rules to the Microsoft Office 365 Identity Platform
relying party trust in ADFS. These rules are required for:
- Hybrid Azure AD device registration
- MDM auto-enrollment via Intune

Without these rules, devices register as hybrid Azure AD joined but MDM URLs remain blank,
preventing Intune enrollment.

.PARAMETER FederatedDomain
Your organization's federated domain (e.g., contoso.com). This must match a verified
federated domain in Entra ID. Check Entra ID > Custom domain names to find yours.

.PARAMETER RelyingPartyName
The name of the ADFS relying party trust. Default: "Microsoft Office 365 Identity Platform"

.PARAMETER WhatIf
Shows what changes would be made without applying them.

.EXAMPLE
.\Add-ADFSDeviceClaimRules.ps1 -FederatedDomain "contoso.com"

Adds device claim rules using contoso.com as the federated domain.

.EXAMPLE
.\Add-ADFSDeviceClaimRules.ps1 -FederatedDomain "contoso.com" -WhatIf

Shows what would be changed without making changes.

.NOTES
Requirements:
- Must run on ADFS server as Administrator
- ADFS service must be running
- Federated domain must be verified in Entra ID

References:
- https://learn.microsoft.com/en-us/azure/active-directory/devices/hybrid-azuread-join-federated-domains
- https://learn.microsoft.com/en-us/azure/active-directory/devices/hybrid-azuread-join-manual


#>

[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory = $true, HelpMessage = "Your federated domain (e.g., contoso.com)")]
[ValidateNotNullOrEmpty()]
[string]$FederatedDomain,

[Parameter(Mandatory = $false)]
[string]$RelyingPartyName = "Microsoft Office 365 Identity Platform"
)

#Requires -RunAsAdministrator

$ErrorActionPreference = "Stop"

Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host "ADFS Device Claim Rules - MDM Enrollment Fix" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Relying Party: $RelyingPartyName" -ForegroundColor Yellow
Write-Host "Federated Domain: $FederatedDomain" -ForegroundColor Yellow
Write-Host ""

# Validate federated domain format
if ($FederatedDomain -notmatch "^[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z]{2,}$") {
Write-Host "ERROR: Invalid domain format. Expected format: contoso.com" -ForegroundColor Red
exit 1
}

# Step 1: Get current relying party trust
Write-Host "[1/5] Getting current relying party trust..." -ForegroundColor Green
try {
$rp = Get-AdfsRelyingPartyTrust -Name $RelyingPartyName
if (-not $rp) {
throw "Relying party trust '$RelyingPartyName' not found. Verify ADFS is configured for Office 365."
}
Write-Host " Found relying party trust." -ForegroundColor Gray
}
catch {
Write-Host "ERROR: $_" -ForegroundColor Red
Write-Host ""
Write-Host "Troubleshooting:" -ForegroundColor Yellow
Write-Host " - Ensure you're running this on the ADFS server" -ForegroundColor Gray
Write-Host " - Verify ADFS service is running: Get-Service adfssrv" -ForegroundColor Gray
Write-Host " - List relying parties: Get-AdfsRelyingPartyTrust | Select Name" -ForegroundColor Gray
exit 1
}

# Step 2: Backup current rules
Write-Host "[2/5] Backing up current rules..." -ForegroundColor Green
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
$backupPath = ".\ADFS_ClaimRules_Backup_$timestamp.txt"
$rp.IssuanceTransformRules | Out-File -FilePath $backupPath -Encoding UTF8
Write-Host " Backup saved to: $backupPath" -ForegroundColor Gray

# Step 3: Check if device rules already exist
Write-Host "[3/5] Checking for existing device claim rules..." -ForegroundColor Green
$existingRules = $rp.IssuanceTransformRules

$hasAccountType = $existingRules -match "accounttype.*DJ"
$hasObjectGuid = $existingRules -match "onpremobjectguid"
$hasPrimarySid = $existingRules -match "primarysid.*issue\(claims"
$hasIssuerId = $existingRules -match "issuerid.*adfs/services/trust"

if ($hasAccountType -or $hasObjectGuid -or $hasPrimarySid -or $hasIssuerId) {
Write-Host " WARNING: Some device claim rules may already exist:" -ForegroundColor Yellow
if ($hasAccountType) { Write-Host " - Account type rule found" -ForegroundColor Yellow }
if ($hasObjectGuid) { Write-Host " - ObjectGUID rule found" -ForegroundColor Yellow }
if ($hasPrimarySid) { Write-Host " - PrimarySID rule found" -ForegroundColor Yellow }
if ($hasIssuerId) { Write-Host " - IssuerID rule found" -ForegroundColor Yellow }
Write-Host ""
$continue = Read-Host " Continue anyway? (y/N)"
if ($continue -ne "y") {
Write-Host " Aborted by user." -ForegroundColor Yellow
exit 0
}
}
else {
Write-Host " No existing device rules found. Proceeding..." -ForegroundColor Gray
}

# Step 4: Define new device claim rules
Write-Host "[4/5] Preparing device claim rules..." -ForegroundColor Green

$deviceClaimRules = @"

@RuleName = "Issue account type for domain-joined computers"
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid", Value =~ "-515$", Issuer =~ "^(AD AUTHORITY|SELF AUTHORITY|LOCAL AUTHORITY)$"]
=> issue(Type = "http://schemas.microsoft.com/ws/2012/01/accounttype", Value = "DJ");

@RuleName = "Issue objectGUID for domain-joined computers"
c1:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid", Value =~ "-515$", Issuer =~ "^(AD AUTHORITY|SELF AUTHORITY|LOCAL AUTHORITY)$"]
&& c2:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer =~ "^(AD AUTHORITY|SELF AUTHORITY|LOCAL AUTHORITY)$"]
=> issue(store = "Active Directory", types = ("http://schemas.microsoft.com/identity/claims/onpremobjectguid"), query = ";objectguid;{0}", param = c2.Value);

@RuleName = "Issue primarySID for domain-joined computers"
c1:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid", Value =~ "-515$", Issuer =~ "^(AD AUTHORITY|SELF AUTHORITY|LOCAL AUTHORITY)$"]
&& c2:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid", Issuer =~ "^(AD AUTHORITY|SELF AUTHORITY|LOCAL AUTHORITY)$"]
=> issue(claim = c2);

@RuleName = "Issue issuerID for domain-joined computers"
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid", Value =~ "-515$", Issuer =~ "^(AD AUTHORITY|SELF AUTHORITY|LOCAL AUTHORITY)$"]
=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/issuerid", Value = "http://$FederatedDomain/adfs/services/trust/");

"@

Write-Host " Device claim rules prepared:" -ForegroundColor Gray
Write-Host " - Account type (DJ)" -ForegroundColor Gray
Write-Host " - On-premises objectGUID" -ForegroundColor Gray
Write-Host " - Primary SID" -ForegroundColor Gray
Write-Host " - Issuer ID (http://$FederatedDomain/adfs/services/trust/)" -ForegroundColor Gray

# Step 5: Apply new rules
Write-Host "[5/5] Applying updated claim rules..." -ForegroundColor Green

$newRules = $existingRules + $deviceClaimRules

if ($PSCmdlet.ShouldProcess($RelyingPartyName, "Update IssuanceTransformRules with device claims")) {
try {
Set-AdfsRelyingPartyTrust -TargetName $RelyingPartyName -IssuanceTransformRules $newRules
Write-Host " Rules applied successfully!" -ForegroundColor Green
}
catch {
Write-Host "ERROR applying rules: $_" -ForegroundColor Red
Write-Host ""
Write-Host "Attempting to restore from backup..." -ForegroundColor Yellow
try {
$backupRules = Get-Content $backupPath -Raw
Set-AdfsRelyingPartyTrust -TargetName $RelyingPartyName -IssuanceTransformRules $backupRules
Write-Host "Backup restored successfully." -ForegroundColor Green
}
catch {
Write-Host "ERROR restoring backup: $_" -ForegroundColor Red
Write-Host "Manual restore required from: $backupPath" -ForegroundColor Red
}
exit 1
}
}

Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host "COMPLETE" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next Steps:" -ForegroundColor Yellow
Write-Host ""
Write-Host " 1. Restart ADFS service (recommended):" -ForegroundColor White
Write-Host " Restart-Service adfssrv" -ForegroundColor Gray
Write-Host ""
Write-Host " 2. On a test device, re-register with Azure AD:" -ForegroundColor White
Write-Host " dsregcmd /leave" -ForegroundColor Gray
Write-Host " Start-Sleep -Seconds 30" -ForegroundColor Gray
Write-Host " dsregcmd /join" -ForegroundColor Gray
Write-Host " Restart-Computer" -ForegroundColor Gray
Write-Host ""
Write-Host " 3. After reboot, verify MDM URLs are populated:" -ForegroundColor White
Write-Host " dsregcmd /status" -ForegroundColor Gray
Write-Host ""
Write-Host " Expected output:" -ForegroundColor Gray
Write-Host " MdmUrl : https://enrollment.manage.microsoft.com/..." -ForegroundColor DarkGray
Write-Host " MdmTouUrl : https://portal.manage.microsoft.com/..." -ForegroundColor DarkGray
Write-Host " MdmComplianceUrl : https://portal.manage.microsoft.com/..." -ForegroundColor DarkGray
Write-Host ""
Write-Host " 4. Check Intune portal for device enrollment (may take 5-15 min)" -ForegroundColor White
Write-Host ""
Write-Host "Rollback:" -ForegroundColor Yellow
Write-Host " If issues occur, restore the backup:" -ForegroundColor White
Write-Host " `$backup = Get-Content '$backupPath' -Raw" -ForegroundColor Gray
Write-Host " Set-AdfsRelyingPartyTrust -TargetName '$RelyingPartyName' -IssuanceTransformRules `$backup" -ForegroundColor Gray
Write-Host " Restart-Service adfssrv" -ForegroundColor Gray
Write-Host ""
Write-Host "Backup location: $backupPath" -ForegroundColor Cyan
Write-Host ""
10 changes: 10 additions & 0 deletions AD/Apply-NameTemplate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Remediation Script

# Get the serial number of the device
$serialNumber = (Get-WmiObject -Class Win32_BIOS).SerialNumber

# Construct the new computer name
$newComputerName = "AP-$serialNumber"

# Rename the computer
Rename-Computer -NewName $newComputerName -Force -Restart
113 changes: 113 additions & 0 deletions AD/Check-ADHealth.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Check-ADHealth.ps1
<#
.SYNOPSIS
PowerShell script for comprehensive Active Directory health monitoring and reporting.

.DESCRIPTION
This script performs comprehensive diagnostics on Active Directory environment by collecting
critical information from domain controllers, including replication status, FSMO roles,
event logs, and system information.

.PARAMETER org
Organization name used for creating output directories and file naming.

.PARAMETER baseDir
Base directory where all output files will be stored. Defaults to D:\Temp.
#>

param(
[Parameter(Mandatory=$true)]
[string]$org,
[Parameter(Mandatory=$false)]
[string]$baseDir = "D:\Temp"
)

# Create base directory structure
$orgDir = Join-Path -Path $baseDir -ChildPath $org
if (-not (Test-Path -Path $orgDir)) {
New-Item -Path $orgDir -ItemType Directory -Force
}

# Function to write logs
function Write-Log {
param([string]$message)
$logPath = Join-Path -Path $orgDir -ChildPath "script_log.txt"
"$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss')): $message" | Out-File -FilePath $logPath -Append
}

# Function to handle errors
function Handle-Error {
param($error)
Write-Log "ERROR: $error"
}

# Start transcript logging
$transcriptPath = Join-Path -Path $orgDir -ChildPath "transcript.log"
Start-Transcript -Path $transcriptPath

try {
# Get all Domain Controllers
Write-Log "Getting Domain Controllers"
$DCs = Get-ADDomainController -Filter *

foreach ($DC in $DCs) {
# Create DC-specific directory
$dcDir = Join-Path -Path $orgDir -ChildPath $DC.Name
if (-not (Test-Path -Path $dcDir)) {
New-Item -Path $dcDir -ItemType Directory -Force
}

# Collect DC specific information
Write-Log "Collecting information for $($DC.Name)"

# System Information
Write-Log "Getting system information for $($DC.Name)"
$sysInfoPath = Join-Path -Path $dcDir -ChildPath "SystemInfo.txt"
systeminfo /S $DC.Name > $sysInfoPath

# Event Logs
Write-Log "Getting event logs for $($DC.Name)"
$appLogPath = Join-Path -Path $dcDir -ChildPath "AppLog.csv"
$sysLogPath = Join-Path -Path $dcDir -ChildPath "SysLog.csv"
Get-EventLog -LogName Application -Newest 5000 -ComputerName $DC.Name | Export-Csv -Path $appLogPath -NoTypeInformation
Get-EventLog -LogName System -Newest 5000 -ComputerName $DC.Name | Export-Csv -Path $sysLogPath -NoTypeInformation

# Hotfixes
Write-Log "Getting hotfixes for $($DC.Name)"
$hotfixPath = Join-Path -Path $dcDir -ChildPath "Hotfixes.csv"
Get-HotFix -ComputerName $DC.Name | Export-Csv -Path $hotfixPath -NoTypeInformation

# Netlogon log
Write-Log "Copying netlogon.log for $($DC.Name)"
$remoteNetlogonPath = "\\$($DC.Name)\c$\windows\debug\netlogon.log"
$localNetlogonPath = Join-Path -Path $dcDir -ChildPath "netlogon.log"
Copy-Item -Path $remoteNetlogonPath -Destination $localNetlogonPath -ErrorAction Continue
}

# Collect AD-wide information
Write-Log "Collecting AD-wide information"

# FSMO Roles
Write-Log "Getting FSMO roles"
$fsmoPath = Join-Path -Path $orgDir -ChildPath "FSMORoles.txt"
netdom query fsmo > $fsmoPath

# Replication Status
Write-Log "Getting replication status"
$replPath = Join-Path -Path $orgDir -ChildPath "ReplicationStatus.txt"
repadmin /showrepl * /csv > $replPath

# Sites and Services
Write-Log "Getting sites and services information"
$sitesPath = Join-Path -Path $orgDir -ChildPath "ADSites.txt"
nltest /server:$env:COMPUTERNAME /dsgetsite > $sitesPath

Write-Log "Script completed successfully"
}
catch {
Handle-Error $_
Write-Log "Script terminated with errors"
}
finally {
Stop-Transcript
}
Loading