Jump to content

Recommended Posts

Posted

Hello,

I'm sure this has been posted a million times however, what's the most simple way to bulk create intake accounts?

 

I have a spreadsheet which takes the students forename, surname and intake year and concatenates them into their username.

We will then have the passwords on inset day, however I have a powershell script to bulk change passwords.

 

all I really need is it to set the following options

 

Forename, Surname, Username, Profile Path, Logon Script, Home Folder (Connect M:), User Cannot Change Password (true), Password Never Expires (True)

 

 

Any tips?

I wouldn't like a massive chunk of code I don't understand either, I've seen these flying around!

Posted

I've got a script for this and it should do everything you need. We set the password to something generic chosen when we are sorting out the csv (usually something like "Welcome1") and force the new accounts to change password at login. I've also got a function built in to check if the username already exists and if so to increment it and check again, this saves a bit of manual work checking each users potential username but if you use something sufficiently unique then you should be fine to just ignore that. It also exports all the created account details to a csv for us to pass out to teachers in case a user does end up with j.smith7 or something as their username.

 

param(
   [Parameter(Mandatory=$true)][string]$Path = $(Read-Host "Enter the path to the csv")
)
Function Check-ADUser{
   [string]$Name = $args[0]
   $ADUser = Get-ADUser -Filter {SamAccountName -eq $Name}


   if ($ADUser) {
       return $ADUser.SamAccountName
   }
   else {
       return 0
   }


}


$Users = Import-Csv -Path $Path
Write-Output "Forename, Surname, Username, Password" >> "NewUsersCreated.csv"
$Users | ForEach-Object  {
   $ShortName = $Forename.Substring(0,1) + "." + $Surname
   $IsADUser = Check-ADUser $ShortName
   $Count = 1
   while ($IsUser -ne 0) {
       $ShortName = $Forename.Substring(0,1) + "." + $Surname + "$Count"
       $IsADUser = Check-ADUser $ShortName
       $Count += 1
   }
   $DisplayName = $_.forename + " " + $_.surname
   $SecureString = ConvertTo-SecureString $_.Password -AsPlainText -Force
   $HomeDirectory = "\\server\path\" + $_.intakeyear + "\" + $ShortName
   $ProfilePath = "\\server\path\" + $_.intakeyear + "\" + $ShortName
   $UserPrincipalName = $ShortName + "@domain.tld"
   $email = $ShortName + "@domain.tld"
   New-ADUser -Name $ShortName -Description $_.description -DisplayName $DisplayName -GivenName $_.forename -HomeDirectory $HomeDirectory -HomeDrive "N:" -ProfilePath $ProfilePath -SamAccountName $ShortName -Surname $_.surname -UserPrincipalName $UserPrincipalName -Path $_.OU -AccountPassword $SecureString -EmailAddress $email -Enabled 1 -CannotChangePassword 1 -PasswordNeverExpires 1
   Start-Sleep -s 10
   Add-ADGroupMember $_.intakeyear -Member $ShortName
   Write-Output "$Forename, $Surname, $ShortName, " + $_.password >> "NewYearUsersCreated.csv"
}

 

I tried to keep the variable names sensible for the purpose they were used but if you've got any questions then let me know.

 

If you don't like a huge block of code then you can pretty much just do it in a single line if the columns of the csv are named correctly and a slightly longer line if they aren't.

  • Thanks 1
Posted

We have an excel spreadsheet which we paste data into from a sims report, it constructs students usernames, passwords and email addresses. In addition it builds the batch files and poweshell commands to create user accounts, home drives, shares, permissions and create their mailbox on exchange online. It then exports these commands to batch files and powershell scripts and creates a master batch file which runs them all.

 

Nice and simple :) (once it's set up)

Posted

Excuse me for asking the obvious, but is this PowerShell?

Also, could you possibly give an example CSV and I can work from that?

 

Thanks!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...