PowerShell: Creating Domains and Domain Controllers

KB ID 0001400

Problem

I needed to spin up some Windows 2016 Servers, and a domain to do some testing. I have promoted hundreds maybe thousands of domain controllers, so I wondered if this time I could do it with PowerShell. It’s actually easier than using the GUI!

Solution

If you were doing this in Server Manager, you would have to add the role first, and PowerShell is no different;

[box]Install-WindowsFeature AD-Domain-Services -IncludeManagementTools[/box]

Then promote the server to a new DC in a new forest;

[box]Install-ADDSForest[/box]

Supply the new domain name and the recovery password. Select ‘Y’ to reboot, go and have a coffee, when finished you will have a new DC in a new domain, ready to log into.

Related Articles, References, Credits, or External Links

NA

Windows Server 2016: Active Directory Recycle Bin

KB ID 0001389

Problem

To be honest we have had the capability to recover deleted active directory objects for ages. It’s just in Windows 2016 things look a bit neater.

Enable Active Directory Recycle Bin

From Server Manager > Tools > Active Directory Administrative Center ,> {Domain-Name} > Enable Recycle Bin.

OK

Note: You may need to restart ADAC before you will be able to see the option greyed out.

Enable Active Directory Recycle Bin with PowerShell

From an administrative PowerShell window;

[box]

Enable-ADOptionalFeature ñIdentity 'CN=Recycle Bin Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=domainx,DC=net' ñScope ForestOrConfigurationSet ñTarget 'domainx.net'

[/box]

Restore an AD Object From the Recycle Bin

I’ve deleted a user , and I want to restore him. From Server Manager > Tools > Active Directory Administrative Center > {Domain-Name} > Deleted Objects.

Locate the deleted object > Restore.

Restore an AD Object From the Recycle Bin with PowerShell

First let’s make sure the item is there to restore!

[box]

Get-ADObject -filter {displayname -eq "Pete Long"} -includedeletedobjects

[/box]

Now we’ve found our deleted user, to restore them, use the same command but ‘pipe’ it to a Restore-ADObject commandlet.

[box]

Get-ADObject -filter {displayname -eq "Pete Long"} -includedeletedobjects | Restore-ADObject

[/box]

 

Related Articles, References, Credits, or External Links

NA