I have created a lot of domain controllers and basic domain services. Some for production, most for testing or lab purposes. This was at first while learning how it all worked and later while teaching courses, testing new techniques and testing things that had nothing to do with the DC but needed to work in a domain.
Last year I started creating scripts so I can set it all up in seconds. Not just installing a domain controller, that isn’t that exiting. But when I have a lab, I want ADobjects, DHCP-leases, DNS-records, that kind of stuff. Creating those with Powershell has been extremely useful and a lot of fun to create.
My colleagues started requesting my scripts for quickly setting up labs, so I decided to clean up what I wrote and publish them for others to use. I’m going to start with AD and DHCP
How to Use
All scripts and CSV-files are on github: https://github.com/Ba4bes/PowerLab
You can download the scripts and use them right away. Below I will give a bit more information about what it all does and how to use it.
AD users and computers
I’ve got a few functions setup for now, I’ll go through them with examples for running them
New-OUstructure -CompanyName "TestCompany" -Verbose
The function sets up a basic OU structure to work with. All OU’s are nested under a base OU with a name of your choice. This one isn’t very flexible, as I have never needed it to be.
New-Users -CSVPath C:\temp\users.csv -UsersOU "Users" -Password 'Pa$$w0rd' -Verbose
This creates 250 users based on a CSVfile that you will find at the repo. The Users have a few basic properties to work with. For lab purposes, all users share the same password and it never expires. This is because I wanted students to log in as the user in a client VM and different passwords complicated stuff.
So just for the record:
Relax, it’s just a lab 🙂
About the CSVfile
It has been created with https://www.fakenamegenerator.com/
I would recommend creating your own based on your own needs. You can even use a language you prefer. This example-file has Dutch names in it. It’s not perfect, but very useful. For this script to work, create a CSV with the following properties:
New-Computers -ComputersCSV c:\temp\computers.csv -ComputersOU "Clients" -Verbose
New-Computers -ComputersCSV C:\temp\servers.csv -ComputersOU "Servers" -Verbose
These two create Computer- and Serveraccounts in the fitting OUs.
If you look at the CSV’s, there’s basically just a list of names. A computeraccount doesn’t need that much information. The accounts don’t do that much, it’s just for simulation purposes.
DHCP
$dhcpparameters = @{
scopename = "TestingScope"
startrange = "10.0.0.100"
endrange = "10.0.0.200"
subnetmask = "255.255.255.0"
dhcpCsvPath = "C:\temp\dhcp.csv"
}
New-DHCPconfiguration @dhcpparameters -Verbose
The dhcp-cmdlet is a bit more straight forward, it does it all. It installs DHCP, configures it and creates leases.
I’ve used the leases for example to simulate a full DHCP-scope.
One thing to look out for: the CSV has hard coded IP-addresses. They need to be in the same range as the IP-addresses defined in the parameters. You can change them easily with notepad replace. This could be done in the script, it’s on my todo-list.
Possible usage
Hyper-V
When I created this script, it was for a hyper-V lab on my local computer. I have made scripts to create VMs and I run these scripts with Powershell correct. So I basically have a function that sets up a populated domain controller in my lab. I plan to go into these scripts at a later time
Azure
When using Devtest lab or just a VM, for now I set up AD Domain services with a different script or DSC. The csv’s complicate things a bit. At this point I just start the DC, copy the files to the VM and run them locally. In the feature I might look in to using storage accounts and Powershell extensions on the VM.
One thing to take into account is that DHCP in Azure can be set up, but I haven’t gotten it to work, as in providing IPs to clients. Azure has its own DHCP service and on top of that, if the VM gets a different IP it might cause trouble when you try to connect to it after.
Other platforms
The stuff I describe above can of course be used on any platform, as you can always run them locally. So VMware or bare metal are no problem.
Conclusion
So that’s about it. Most usage should be self explanatory, but if you have questions, don’t hesitate to ask in the comments.
I’m planning to clean up and share more of these scripts in the near feature.
Pingback:PowerLab: Quickly configure servers in HyperV using PowerShell direct – 4bes.nl