Anonymous
  • The main thing that sticks out to me with this code is the repetition of lines related to your yearly Intake stuff.  You can cut out a lot of lines by using a simple for loop...

    for ($year = 2008; $year -le 2020; $year++) {

       New-ADOrganizationalUnit -Name "Intake $year" -path "OU=Student,OU=Users,$Domain_Establishment"

       New-ADGroup -Path "OU=Security Groups,$($Domain_Establishment)" -Name "Intake $year" -GroupCategory Security -GroupScope Global -DisplayName "Intake $year" -Description "Intake $year"

       New-ADUser -Name "Intake$($year)Template" -SamAccountName "Intake$($year)Template" -GivenName "Intake $year" -Surname 'Template' -DisplayName "Intake $year Template" -Enabled $true -Path "OU=Intake $year,OU=Student,OU=Users,$Domain_Establishment" -AccountPassword $TemplateUser_Pwd_Enc -ChangePasswordAtLogon $false

       Add-ADGroupMember -Identity 'Students' -Member "Intake$($year)Template"

       Add-ADGroupMember -Identity "Intake $year" -Member "Intake$($year)Template"  

       New-Item -ItemType Directory -Path "$Folder_Drive_Letter\Users\Students\Intake $year"

       New-SmbShare -Name "Intake$($year)`$" -Path "$Folder_Drive_Letter\Users\Students\Intake $year" -FullAccess 'Everyone'

    }