Last active
December 7, 2022 15:20
-
-
Save doctordns/910895ade4fb97f7060f2910a2e16b06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ChatGPT was asked to create a script: | |
# "Write a powershell script to install AD and create users, groups, OUs and GPOs" | |
# | |
# This is what it came up with! | |
"Write a powershell script to install AD and create users, groups, OUs and GPOs" | |
this is what it came up with! | |
# Install Active Directory | |
Import-Module ADDSDeployment | |
Install-ADDSForest -CreateDnsDelegation:$false | |
-DatabasePath "C:\Windows\NTDS" -DomainMode "Win2012R2" | |
-DomainName "mydomain.local" -DomainNetbiosName "mydomain" | |
-ForestMode "Win2012R2" -InstallDns:$true | |
-LogPath "C:\Windows\NTDS" -NoRebootOnCompletion:$false | |
-SysvolPath "C:\Windows\SYSVOL" ` | |
-Force:$true | |
# Create Users | |
Import-Module ActiveDirectory | |
$users = @( | |
@{name="user1"; password="P@ssw0rd1"}, | |
@{name="user2"; password="P@ssw0rd2"}, | |
@{name="user3"; password="P@ssw0rd3"}, | |
@{name="user4"; password="P@ssw0rd4"}, | |
@{name="user5"; password="P@ssw0rd5"}, | |
) | |
foreach ($user in $users) { | |
New-ADUser -Name $user.name | |
-AccountPassword (ConvertTo-SecureString $user.password -AsPlainText -Force) -ChangePasswordAtLogon $true | |
-Enabled $true | |
} | |
# Create Groups | |
$groups = @( | |
"group1", | |
"group2", | |
"group3", | |
"group4", | |
"group5", | |
) | |
foreach ($group in $groups) { | |
New-ADGroup -Name $group | |
-GroupCategory Security ` | |
-GroupScope Global | |
} | |
# Create OUs | |
$ous = @( | |
"ou1", | |
"ou2", | |
"ou3", | |
"ou4", | |
"ou5", | |
) | |
foreach ($ou in $ous) { | |
New-ADOrganizationalUnit -Name $ou | |
-Path "DC=mydomain,DC=local" | |
} | |
# Create GPOs | |
$gponames = @( | |
"gpo1", | |
"gpo2", | |
"gpo3", | |
"gpo4", | |
"gpo5", | |
) | |
foreach ($gpo in $gponames) { | |
New-GPO ` | |
-Name $gpo | |
} | |
# Link GPOs to OUs | |
$gpolinks = @( | |
@{gpo="gpo1"; ou="ou1"}, | |
@{gpo="gpo2"; ou="ou2"}, | |
@{gpo="gpo3"; ou="ou3"}, | |
@{gpo="gpo4"; ou="ou4"}, | |
@{gpo="gpo5"; ou="ou5"}, | |
) | |
foreach ($link in $gpolinks) { | |
New-GPLink -Name $link.gpo | |
-Target $link.ou | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ChatGPT was asked:
"Write a powershell script to install AD and create users, groups, OUs and GPOs"
this is what it came up with!