Last active
November 6, 2017 20:22
-
-
Save bohack/67a2ba0779b894a622dfdfdda49f3ff7 to your computer and use it in GitHub Desktop.
Create Users for Lab Redux
This file contains hidden or 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
# Create users and Groups for Lab | |
# Bohack | |
# 11/6/17 | |
Import-Module ActiveDirectory | |
# Variables for Creation | |
$rtdomain = "DC=Netmind,DC=Local" | |
$orgrt = "Netmind" | |
$orgpath = "OU=Netmind,$rtdomain" | |
$upn = "@netmind.local" | |
# Create the OU structure | |
Echo "Creating OU Structure" | |
New-ADOrganizationalUnit -Name $orgrt -Path $rtdomain | |
New-ADOrganizationalUnit -Name Users -Path $orgpath | |
New-ADOrganizationalUnit -Name Groups -Path $orgpath | |
New-ADOrganizationalUnit -Name Servers -Path $orgpath | |
# Create the groups | |
Echo "Creating Groups" | |
New-ADGroup -Name "IT Department" -SamAccountName ITDept -GroupScope DomainLocal -Path “OU=Groups,$orgpath" | |
New-ADGroup -Name "Sales" -SamAccountName Sales -GroupScope DomainLocal -Path “OU=Groups,$orgpath" | |
New-ADGroup -Name "Marketing" -SamAccountName Marketing -GroupScope DomainLocal -Path “OU=Groups,$orgpath" | |
New-ADGroup -Name "Research" -SamAccountName Research -GroupScope DomainLocal -Path “OU=Groups,$orgpath" | |
Function CreateUsers { | |
Param | |
([string]$FirstName,[string]$Department,[string]$Group,[int]$Count) | |
For ($Count=0; $Count -le 20; $Count++) { | |
Echo "Creating User $Firstname $Count" | |
New-ADUser -Name "$Firstname$Count" -AccountPassword (ConvertTo-SecureString “Password20!” -AsPlainText -Force) -ChangePasswordAtLogon $false -Company “$orgrt” -DisplayName “$Firstname$Count” -Enabled $true -SamAccountName $Firstname$Count -Path “OU=Users,$orgpath” -Givenname $Firstname -Surname $Count -userprincipalname (“$Firstname$Count” + $upn) -department "$Department” -description "$Firstname$Count” | |
Add-ADGroupMember -Identity $Group -Member $Firstname$Count | |
} | |
} | |
# Create the users | |
CreateUsers -FirstName Tech -Department IT -Group ITDept -Count 20 | |
CreateUsers -FirstName Sales -Department Sales -Group Sales -Count 20 | |
CreateUsers -FirstName Research -Department Research -Group Research -Count 20 | |
CreateUsers -FirstName Marketing -Department Marketing -Group Marketing -Count 20 | |
# Add the users to collateral groups | |
#Echo "Adding Users to collateral groups" | |
#Add-ADGroupMember -Identity Research -Member techfour |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment