Release date: December 22nd 2022
Welcome to my Microsoft Tips & Tricks section. I recently experienced a complete hardware crash in my old lab, and had to do a complete rebuild. Although this was sad, it gave me the opportunity to do it by scripting this time. This involved recreating the admin users and groups, and adding the admin users to the correct admin group, as shown below.
The script below uses a csv file with the following data:
- User
- Group
Next, using the script below, I easily added the admin users to their corresponding admin groups. NOTE: The user I ran this script with had Domain Admin permissions, otherwise this wouldn’t have worked.
$server = "fqdn ad controller"
Import-Module ActiveDirectory
$file = Import-Csv "<Path to csv fil>.csv" -Delimiter ";"
Write-Host *** Input file contains $file.Count lines.
foreach ($row in $file) {
Write-Host $row.user will be processed -NoNewline
$user = $row.User
$grp = $row.Group
Write-Host ... $user ... $grp -NoNewline
Add-ADGroupMember -server $server -identity $grp -Members $user -Confirm:$false
Write-Host ... done.
}
write-host *** All selectable records processed
Now that I had created the Admin Users and Groups, I could proceed with creating vm’s and installing the servers in my domain, which I also did by using a script, detailed here: VMware PowerCLI – Deploy and setup multiple servers
Big thanks to: Peter Buijsman’s: Quickly add users to groups from CSV via Powershell
Microsoft Tips & Tricks section
Disclaimer: Every tips/tricks/posting I have published here, is tried and tested in different it-solutions. It is not guaranteed to work everywhere, but is meant as a tip for other users out there. Remember, Google is your friend and don’t be afraid to steal with pride! Feel free to comment below as needed.