2015-10-21 19:31:17 +02:00
|
|
|
############################################
|
2015-10-22 09:00:03 +02:00
|
|
|
## Script by Daniel Løvbrøtte Olsen, 1ELA ##
|
2015-10-21 19:31:17 +02:00
|
|
|
## For Fredrik Refstie ##
|
|
|
|
############################################
|
2015-10-23 23:59:14 +02:00
|
|
|
#Imports a comma separated file, COMMA SEPARATED NOT SEMI;COLON
|
2015-10-21 19:31:17 +02:00
|
|
|
$Users = Import-Csv .\Users.csv
|
2015-10-23 23:59:14 +02:00
|
|
|
#Loops through each of the rows, or objects really.
|
2015-10-21 19:31:17 +02:00
|
|
|
forEach ($User in $Users)
|
|
|
|
{
|
2015-10-21 20:06:57 +02:00
|
|
|
$firstname = $User.first
|
2015-10-23 23:59:14 +02:00
|
|
|
#Select two first of first name and store it in $first
|
2015-10-21 20:06:57 +02:00
|
|
|
$first = $firstname[0..1]
|
|
|
|
$lastname = $User.last
|
2015-10-23 23:59:14 +02:00
|
|
|
#Select three first of lastname and store it in $last
|
2015-10-21 20:06:57 +02:00
|
|
|
$last = $lastname[0..2]
|
2015-10-23 23:59:14 +02:00
|
|
|
#Merge the two things
|
2015-10-21 19:31:17 +02:00
|
|
|
$username = "$first$last"
|
2015-10-22 10:37:49 +02:00
|
|
|
#Hack to fix weird spaces between characters
|
2015-10-21 19:31:17 +02:00
|
|
|
$username = $username -replace " ", ""
|
2015-10-23 23:59:14 +02:00
|
|
|
#Write the command to a batfile to run in a normal cmd window
|
2015-10-29 13:21:31 +01:00
|
|
|
"dsadd user `"cn=$username, ou=Illuminati, dc=datavg2, dc=local`" -fn $firstname -ln $lastname -pwd Admin123" | out-file run.bat -Encoding "UTF8" -Append
|
2015-10-21 19:31:17 +02:00
|
|
|
}
|
|
|
|
"echo Script has finished running, thanks based Daniel in 1ELA for making our lives easier" | out-file run.bat -Encoding "UTF8" -Append
|
|
|
|
"PAUSE" | out-file run.bat -Encoding "UTF8" -append
|
2015-10-23 23:59:14 +02:00
|
|
|
#Turn off safeties
|
2015-10-21 19:31:17 +02:00
|
|
|
"@ECHO OFF" | out-file run.bat -Encoding "UTF8" -append
|
2015-10-23 23:59:14 +02:00
|
|
|
#Delete yourself
|
2015-10-21 19:31:17 +02:00
|
|
|
"DEL `"%~f0`"" | out-file run.bat -Encoding "UTF8" -append
|
2015-10-23 23:59:14 +02:00
|
|
|
#Start the batfile you just created
|
2015-10-22 09:00:03 +02:00
|
|
|
Start-Process "cmd.exe" "/c run.bat"
|