Загрузка данных
$Out = "C:\AD_EXPORT"
New-Item $Out -ItemType Directory -Force | Out-Null
# =========================
# 1. DOMAIN / FOREST
# =========================
Get-ADDomain |
Format-List * |
Out-File "$Out\domain.txt" -Encoding UTF8
Get-ADForest |
Format-List * |
Out-File "$Out\forest.txt" -Encoding UTF8
netdom query fsmo |
Out-File "$Out\fsmo_roles.txt" -Encoding UTF8
Get-ADDomainController -Filter * |
Select HostName,Site,IPv4Address,IPv6Address,OperatingSystem,
OperatingSystemVersion,IsGlobalCatalog,IsReadOnly |
Export-Csv "$Out\domain_controllers.csv" -NoTypeInformation -Encoding UTF8
Get-ADTrust -Filter * |
Select Name,Source,Target,Direction,TrustType,ForestTransitive |
Export-Csv "$Out\trusts.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 2. SITES / SUBNETS
# =========================
Get-ADReplicationSite -Filter * |
Select Name,DistinguishedName |
Export-Csv "$Out\sites.csv" -NoTypeInformation -Encoding UTF8
Get-ADReplicationSubnet -Filter * |
Select Name,Site,Location,DistinguishedName |
Export-Csv "$Out\subnets.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 3. USERS
# =========================
Get-ADUser -Filter * -Properties `
Enabled,LastLogonDate,PasswordLastSet,PasswordNeverExpires,
PasswordExpired,PasswordNotRequired,LockedOut,Created,
Modified,ServicePrincipalName,MemberOf,DistinguishedName |
Select SamAccountName,Name,Enabled,LockedOut,
LastLogonDate,PasswordLastSet,PasswordNeverExpires,
PasswordExpired,PasswordNotRequired,Created,Modified,
DistinguishedName |
Export-Csv "$Out\users.csv" -NoTypeInformation -Encoding UTF8
Get-ADUser -Filter * -Properties LastLogonDate |
Where-Object {
$_.Enabled -eq $false -or
$_.LastLogonDate -lt (Get-Date).AddDays(-90)
} |
Select SamAccountName,Name,Enabled,LastLogonDate,DistinguishedName |
Export-Csv "$Out\inactive_users.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 4. COMPUTERS
# =========================
Get-ADComputer -Filter * -Properties `
OperatingSystem,OperatingSystemVersion,IPv4Address,
Enabled,LastLogonDate,Created,Modified,DistinguishedName |
Select Name,DNSHostName,OperatingSystem,OperatingSystemVersion,
IPv4Address,Enabled,LastLogonDate,Created,Modified,
DistinguishedName |
Export-Csv "$Out\computers.csv" -NoTypeInformation -Encoding UTF8
Get-ADComputer -Filter * -Properties LastLogonDate |
Where-Object {
$_.Enabled -eq $false -or
$_.LastLogonDate -lt (Get-Date).AddDays(-90)
} |
Select Name,DNSHostName,Enabled,LastLogonDate,DistinguishedName |
Export-Csv "$Out\inactive_computers.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 5. GROUPS
# =========================
Get-ADGroup -Filter * -Properties GroupScope,GroupCategory,Description |
Select Name,SamAccountName,GroupScope,GroupCategory,
Description,DistinguishedName |
Export-Csv "$Out\groups.csv" -NoTypeInformation -Encoding UTF8
$GroupMembers = foreach ($g in Get-ADGroup -Filter *) {
try {
Get-ADGroupMember $g -Recursive | ForEach-Object {
[PSCustomObject]@{
Group = $g.SamAccountName
Member = $_.SamAccountName
Name = $_.Name
ObjectClass = $_.ObjectClass
DistinguishedName = $_.DistinguishedName
}
}
} catch {}
}
$GroupMembers |
Export-Csv "$Out\group_members.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 6. PRIVILEGED GROUPS
# =========================
$PrivGroups = @(
"Domain Admins",
"Enterprise Admins",
"Schema Admins",
"Administrators",
"Account Operators",
"Server Operators",
"Backup Operators",
"Print Operators",
"Group Policy Creator Owners"
)
$Priv = foreach ($g in $PrivGroups) {
try {
Get-ADGroupMember $g -Recursive | ForEach-Object {
[PSCustomObject]@{
Group = $g
Member = $_.SamAccountName
Name = $_.Name
ObjectClass = $_.ObjectClass
}
}
} catch {}
}
$Priv |
Export-Csv "$Out\privileged_members.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 7. OU
# =========================
Get-ADOrganizationalUnit -Filter * -Properties Description |
Select Name,Description,DistinguishedName |
Export-Csv "$Out\ous.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 8. PASSWORD / KERBEROS
# =========================
Get-ADDefaultDomainPasswordPolicy |
Format-List * |
Out-File "$Out\default_password_policy.txt" -Encoding UTF8
Get-ADFineGrainedPasswordPolicy -Filter * |
Format-List * |
Out-File "$Out\fine_grained_password_policies.txt" -Encoding UTF8
# =========================
# 9. SPN / SERVICE ACCOUNTS
# =========================
Get-ADUser -Filter * -Properties ServicePrincipalName |
Where-Object {$_.ServicePrincipalName.Count -gt 0} |
Select SamAccountName,Name,Enabled,ServicePrincipalName,DistinguishedName |
Export-Csv "$Out\service_accounts_spn.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 10. GPO
# =========================
Get-GPO -All |
Select DisplayName,Id,GpoStatus,CreationTime,ModificationTime |
Export-Csv "$Out\gpo_list.csv" -NoTypeInformation -Encoding UTF8
Get-GPOReport -All -ReportType Xml -Path "$Out\gpo_all.xml"
Get-GPOReport -All -ReportType Html -Path "$Out\gpo_all.html"
# =========================
# 11. REPLICATION / HEALTH
# =========================
dcdiag /v > "$Out\dcdiag_full.txt"
repadmin /replsummary > "$Out\repadmin_summary.txt"
repadmin /showrepl * /csv > "$Out\repadmin_showrepl.csv"
repadmin /showrepl * /verbose > "$Out\repadmin_showrepl_verbose.txt"
Get-ADReplicationFailure -Target * -Scope Forest |
Export-Csv "$Out\replication_failures.csv" -NoTypeInformation -Encoding UTF8
Get-ADReplicationPartnerMetadata -Target * -Scope Forest |
Select Server,Partner,Partition,LastReplicationAttempt,
LastReplicationSuccess,LastReplicationResult,
ConsecutiveReplicationFailures |
Export-Csv "$Out\replication_partners.csv" -NoTypeInformation -Encoding UTF8
# =========================
# 12. DNS
# =========================
Get-DnsServerZone |
Select ZoneName,ZoneType,IsDsIntegrated,IsReverseLookupZone,
DynamicUpdate,ReplicationScope |
Export-Csv "$Out\dns_zones.csv" -NoTypeInformation -Encoding UTF8
Get-DnsServerForwarder |
Format-List * |
Out-File "$Out\dns_forwarders.txt" -Encoding UTF8
ipconfig /all > "$Out\ipconfig_dc.txt"
# =========================
# 13. BASIC SERVER INFO
# =========================
systeminfo > "$Out\server_systeminfo.txt"
Get-WindowsFeature |
Where-Object Installed |
Select Name,DisplayName |
Export-Csv "$Out\installed_roles_features.csv" -NoTypeInformation -Encoding UTF8