AD Functional level and DC list

Functional Level

Check Forest functional Level

Get-ADForest | ft ForestMode

Check Domain functional Level

Get-ADDomain | ft DomainMode

Upgrade / set Functional level

Set-ADForestMode –ForestMode <desired forest level>
Set-ADDomainMode –DomainMode <desired domain level>

Show all DC servers

netdom query dc
DSQUERY Server -o rdn

FSMO

Get FSMO roles

Get-ADDomain | select InfrastructureMaster, PDCEmulator, RIDMaster
Get-ADForest | select DomainNamingMaster, SchemaMaster

Transfer FSMO

# Transfer PDCEmulator 
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" PDCEmulator
# Transfer RIDMaster
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" RIDMaster
# Transfer InfrastrctureMaster
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" Infrastructuremaster
#  Transfer DomainNamingMaster
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" DomainNamingmaster
# Transfer SchemaMaster
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" SchemaMaster

Seize FSMO

The different between transfering and seizeing the FSMO role is by adding -force argument at the end of command. You can use the same command to perform one-by-one process,

Move-ADDirectoryServerOperationMasterRole -Identity "DC01" PDCEmulator -Force
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" RIDMaster -Force
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" Infrastructuremaster -Force
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" DomainNamingmaster -Force
Move-ADDirectoryServerOperationMasterRole -Identity "DC01" SchemaMaster -Force

or moving all together:

Move-ADDirectoryServerOperationMasterRole -Identity AD01 -OperationMasterRole SchemaMaster, DomainNamingMaster, PDCEmulator, RIDMaster, InfrastructureMaster -Force

AD Healtcheck

Repadmin

repadmin /showrepl -> Check replication status
repadmin /replsum -> Check Replication summary
repadmin /replsum * -> All replication summary information from all DCs
repadmin /queue -> Check Replication Queue
repadmin /kcc *  -> Forces the KCC on targeted domain controller(s) to immediately recalculate its inbound replication topology
Repadmin /showbackup * -> Find the last time your DCs were backed up, by reading the DSASignature attribute from all servers
repadmin /showoutcalls * -> Displays calls that have not yet been answered, made by the specified server to other servers
repadmin /bridgeheads * /verbose -> List the Topology information of all the bridgehead servers
repadmin /istg * /verbose -> Inter Site Topology Generator Report
repadmin /failcache * -> Displays a list of failed replication events detected by the Knowledge Consistency Checker (KCC).
Repadmin /showtrust * -> Lists all domains trusted by a specified domain
repadmin /bind * -> Displays the replication features for, a directory partition on a domain controller.
repadmin /syncall -> Sync between AD server on the same site.
repadmin /syncall /Adep -> Sync AD multiple sites

A = All Partitions
e = Enterprise (Cross Site)
D = Identify servers by distinguished name in messages
P = Push

DCDIAG

dcdiag /c /e /v -> Dcdiag analyzes the state of domain controllers in a forest or enterprise and reports any problems to help in troubleshooting
Dcdiag /v /c /d /e /s:DCName >c:\dcdiag.log

- DNS Dynamic Update
dcdiag /test:dns /v /s:<DCName> /DnsDynamicUpdate
dcdiag /test:dns /v /e /f:<File name.txt>
dcdiag /test:dns /v /s:<DCName> /DnsDynamicUpdate
dcdiag /v /test:Advertising /test:SysVolCheck -> Sysvolcheck

AD DNS

  • Force DNS Propagation Update.
dnscmd /zoneupdatefromds domain.com
dnscmd /zoneupdatefromds sub.domain.com

AD Object Management

OU

Get OU

Get-ADOrganizationalUnit -Filter * | ft name
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | Format-Table Name, DistinguishedName -A

Get child OU

Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=Sales,OU=UserAccounts,DC=FABRIKAM,DC=COM' -SearchScope OneLevel | Format-Table Name,Country,PostalCode,City,StreetAddress,State

AD Computer

All computer

# All computer on entire domain
Get-ADComputer -Filter * | ft
Get-ADComputer -filter * -Properties * | Select Name, OperatingSystem
# All computer on specific OU
Get-ADComputer -filter * -SearchBase "OU=WORKSTATION,DC=amanulloh,DC=com" -Properties OperatingSystem | Sort Name | Format-Table Name,Enabled,OperatingSystem -AutoSize
# Export to html
Get-ADComputer -Filter {OperatingSystem -Like '*Windows Server 2012*' } -Properties * | Select-Object Name,OperatingSystem | ConvertTo-Html | Out-File C:\ps\ad_computers_list.html
# Check computer Last logon
Get-ADComputer -Filter * -Properties * | FT Name, LastLogonDate -Autosize
Get-ADComputer -Filter * -Properties * | Sort LastLogonDate | FT Name, LastLogonDate -Autosize
# Get AdComputer Operating System filter by Server
Get-ADComputer -Filter {OperatingSystem -like '*Windows Server 2022*'}
Get-ADComputer -Filter {OperatingSystem -like '*Windows Server 2022*'} | ft Name,DistinguishedName
# Specific Computer
Get-ADComputer -Identity $servername
Get-ADComputer -Identity $servername -Properties *
Get-ADComputer -identity $servername -Properties * | FT Name, LastLogonDate -Autosize
# Get ADComputer member
Get-ADComputer -Filter * -Properties * | Get-Member

Get a list of computers and export it

  • Export to TXT file
Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server 2022*' } -Properties OperatingSystem | Select DNSHostName, OperatingSystem | Format-Table -AutoSize C:\Script\server_system.txt
  • Export to CSV
Get-ADComputer -Filter * -Property * | Select-Object Name,OperatingSystem,OperatingSystemServicePack | Export-CSV All-Windows.csv -NoTypeInformation -Encoding UTF8
  • Export to HTML.
Get-ADComputer -Filter {OperatingSystem -Like '*Windows Server 2012*' } -Properties * | Select-Object Name,OperatingSystem | ConvertTo-Html | Out-File C:\ps\ad_computers_list.html

Get a list of servers in the domain with the OS version, Service Pack installed. and IP address:

Get-ADComputer -Filter 'operatingsystem -like "*Windows server*" -and enabled -eq "true"' -Properties  Name,Operatingsystem, OperatingSystemVersion, OperatingSystemServicePack,IPv4Address | Sort-Object -Property Operatingsystem | Select-Object -Property Name,Operatingsystem, OperatingSystemVersion, OperatingSystemServicePack, IPv4Address| ft -Wrap –Auto

List the serial number

Get-ADComputer -Filter 'operatingsystem -like "*Windows server*" -and enabled -eq "true"' | Select-Object Name | Foreach-Object {Get-CimInstance Win32_Bios -ComputerName $_.Name -ErrorAction SilentlyContinue | Select-Object PSComputerName,SerialNumber}

Get model and manufacturer and add into a txt file.

$Computers = Get-ADComputer -Filter {OperatingSystem -Like '*Windows Server*'}
Foreach ($Computer in $Computers)
{
$Hostname = $Computer.Name
$ComputerInfo = (Get-WmiObject -Computername $Hostname Win32_ComputerSystem)
$Manufacturer = $Computer.Manufacturer
$Model = $Computer.Model
Write-Host "Name: $Hostname"
Write-Host "Manufacturer: $Manufacturer"
Write-Host "Model: $Model"
Write-Host " "
$Content = "$Hostname;$Manufacturer;$Model"
Add-Content -Value $Content -Path "C:\PS\ServersInfo.txt"
}
Get-ADComputer -Filter {OperatingSystem -Like '*Windows Server 2012*' } -Properties * | Select-Object Name,OperatingSystem | ConvertTo-Html | Out-File C:\ps\ad_computers_list.html

Get AD Computer and run specific command (Gpupdate /force)

get-adcomputer -SearchBase "OU=Servers,DC=woshub,DC=com" -Filter * | %{ Invoke-Command -Computer $_.Name -ScriptBlock {gpupdate /force} }

Check Last AD user password Changes

  • All Users.
Get-ADUser -filter *  -properties PwdLastSet  | sort Name | ft Name,@{Name='PwdLastSet';Expression={[DateTime]::FromFileTime($_.PwdLastSet)}}
  • On specific OU
Get-ADUser -Filter * -Properties PasswordLastSet -SearchBase "distinguishedName" | ft Name,PasswordLastSet 

Password Policy

Get-ADFineGrainedPasswordPolicy -Filter *
Get-ADUserResultantPasswordPolicy User
Get-ADDomain | Get-ADObject -Properties * | select *pwd* -> Check Minimum password on the domain.

SPN

setspn -l hostname -> List SPN
setspn -r hostname -> Resetting SPNs
setspn -s service/name hostname -> Adding SPN
setspn -d service/name hostname -> Remove SPN