Monday, July 15, 2019

Quickly get the Domain Controllers via Powershell

I use this all the time, and get-adDomainControllers is a broken command, so this quickly grabs the DCs and can get other info if needed.

$AllDCS=[system.directoryservices.activedirectory.Forest]::GetCurrentForest().domains | %{$}

$AllDCS | foreach {
    Get-ADdomaincontroller $_.trim() | select Hostname, IPv4Address


Monday, January 14, 2019

Backup of Active Directory and move to new test environment

#export schema
ldifde -f PRODSchema.ldif -d CN=Schema,CN=Configuration,DC=ORG,DC=int

Export the organizational units from the source domain
#ldifde -f exportOu.ldf -s Server1 -d "dc=ORG,dc=int" -p subtree -r "(objectCategory=organizationalUnit)" -l "cn,objectclass,ou"
ldifde -f ProdOu.ldf -d "dc=dec,dc=int" -p subtree -r "(objectCategory=organizationalUnit)"

Export the user accounts from the source domain
#ldifde -f Exportuser.ldf -s Server1 -d "dc=ORG,dc=int" -p subtree -r "(&(objectCategory=person)(objectClass=User)(givenname=*))" -l "cn,givenName,objectclass,samAccountName"
ldifde -f Produser.ldf -d "dc=dec,dc=int" -p subtree -r "(&(objectCategory=person)(objectClass=User)(givenname=*))"

Search and replace to the new AD name

ldifde -i -f D:\TEMP\DiffSchema.ldf

#ou structure
ldifde -i -k -f D:\TEMP\ProdOu.ldf

ldifde -i -k -f D:\TEMP\Produser2.ldf

Blog Archive