Archive for the ‘Powershell’ Category

Active Directory quick queries via Powershell

Tuesday, October 6th, 2015

Here is reference to a few quick AD queries via Powershell’s “one command”.

Forest basic info:

Get-ADForest | Select Name, RootDomain, DomainNamingMaster, SchemaMaster, @{l='FFL';e={$_.ForestMode}} | Format-Table -autosize

Domains’ basic info from entire forest:

Get-ADForest | Select -ExpandProperty Domains | Get-ADDomain | Select DNSRoot, NetBIOSName, PDCEmulator, RIDMaster, InfrastructureMaster, @{l='DFL';e={$_.DomainMode}} | Format-Table -autosize

List of Domain Controllers:

Get-ADDomainController -filter * | Select Name, Domain, @{l='IPv4';e={$_.IPv4Address}}, Site, @{l='GC';e={$_.IsGLobalCatalog}}, @{l='OS';e={$_.OperatingSystem}}, @{l='OS Ver.';e={$_.OperatingSystemVersion}} | FT -auto

"myDomain" | Get-ADDomain | Select -Expand ReplicaDirectoryServers

DCs numbers per domains in whole forest:

Get-ADForest | Select -Expand Domains | Get-ADDomain | Select DNSRoot, @{l='DCs';e={ ($_.ReplicaDirectoryServers).Count}} | Format-Table -autosize

Sites:

Get-ADReplicationSite -Filter * | Select Name, @{l='ISTG';e={($_.InterSiteTopologyGenerator).Split(",")[1].Replace("CN=","")}} , Description | Sort Name | Format-Table -autosize

Subnets:

Get-ADReplicationSubnet -Filter * | Select Name, @{l='Site';e={($_.Site).Split(',')[0]}} | Sort Site, Name | Format-Table -Group Site -autosize

Site links:

Get-ADReplicationSiteLink -Filter * | Select Name, Cost, @{l = 'Interval';e={$_.ReplicationFrequencyInMinutes}}, @{l='Sites';e={$_.SitesIncluded}} | Sort Name | Format-Table -autosize

Get-ADReplicationSiteLink -Filter * | Select Name, Cost, @{l = 'Interval';e={$_.ReplicationFrequencyInMinutes}}, @{l='Sites';e={ForEach-Object {($_.SitesIncluded | Get-ADReplicationSite | Select -ExpandProperty Name).Replace("CN=","")}}} | Sort Name | Format-Table -autosize

Connection objects on <myDC>:

Get-ADReplicationConnection -Filter * -Server  <myDC> | Select @{l='To';e={ ($_.ReplicateToDirectoryServer).Split(",")[0].Replace("CN=","")}} , @{l='From';e={ ($_.ReplicateFromDirectoryServer).Split(",")[1].Replace("CN=","") }}, Name, AutoGenerated | Format-Table -autosize

Replication queue on <myDC>:

Get-ADReplicationQueueOperation -Server <myDC>

Replication status on <myDC>:

Get-ADReplicationPartnerMetadata -Target <myDC>

Get-ADReplicationPartnerMetadata -Target <myDC> | Select Server, @{l='From';e={ $_.Partner.Split(",")[1].Replace("CN=","")}}, Partition, LastReplicationSuccess, LastReplicationAttempt | Format-Table -autosize

Replication status in whole forest:

Get-ADForest | Select -Expand Domains | Get-ADDomain | Select ReplicaDirectoryServers | Get-ADReplicationPartnerMetadata | Select Server, @{l='From';e={ $_.Partner.Split(",")[1].Replace("CN=","")}}, Partition, LastReplicationSuccess, LastReplicationAttempt | Format-Table -autosize