Opret en .csv fil (Kanlaves i Notepad) med dette indhold:
Name;Password;Full Name;Description
Name2;Password2;Full Name2;Description2
Gem den som: "Users.csv"
Kopier scriptet herunder og gem det som: "CreateUsers.vbs"
'***** Script start *****
Const strGroup = "Administrators"
Const strInputFile = "Users.csv"
Const strOutputFile = "Fejl.txt"
Const BrugerNavn = 0
Const Password = 1
Const FuldtNavn = 2
Const Beskrivelse = 3
Const ForReading = 1
Const ForAppending = 2
strResponse = MsgBox ("Start oprettelsen af brugere? ", 36, "Brugeroprettelse")
If strResponse <> 6 then WScript.Quit
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oUserList = oFSO.OpenTextFile (strInputFile, ForReading)
Set oUserError = oFSO.OpenTextFile (strOutputFile, ForAppending, True)
oUserError.WriteLine("Følgende brugere er ikke oprettet, da brugernavnet allerede var i brug:")
LinesRead = 0
UsersCreated = 0
Set WshNetwork = CreateObject("WScript.Network")
strComputername = WshNetwork.ComputerName
Do Until oUserList.AtEndOfStream
strNextLine = oUserList.Readline
LinesRead = LinesRead + 1
arrUserList = Split(strNextLine , ";")
If UBound(arrUserList) > 0 Then
If Len(arrUserList(ForNavn)) > 0 And Len(arrUserList(EfterNavn)) > 0 Then
If UserExist(arrUserList(Brugernavn)) Then
oUserError.WriteLine(strNextLine)
Else
Set oAccount = GetObject("
WinNT://" & strComputername & ",computer")
Set oUser = oAccount.Create("user", arrUserList(BrugerNavn))
oUser.SetPassword arrUserList(Password)
oUser.SetInfo
oUser.Put "FullName", arrUserList(FuldtNavn)
oUser.Put "Description", arrUserList(Beskrivelse)
oUser.Put "UserFlags", (oUser.Get("UserFlags") Or &H10000)
oUser.Put "UserFlags", (oUser.Get("UserFlags") Or &H00040)
oUser.SetInfo
Set oGroup = GetObject("
WinNT://" & strComputername & "/" & strGroup & ",group")
oGroup.Add (oUser.ADsPath)
Set oUser = GetObject("
WinNT://" & strComputername & "/" & arrUserList(Brugernavn) & ",user")
UsersCreated = UsersCreated + 1
End If
End If
End If
Loop
oUserList.Close
oUserError.Close
strMessage = "Der er oprettet " & UsersCreated & " brugere. " & Chr(13) & Chr(13)
If LinesRead > UsersCreated Then
strMessage = strMessage & "Alle brugere blev ikke oprettet, se filen: " & strOutputFile & " "& Chr(13)
End If
strResponse = MsgBox (strMessage, 64, "Brugeroprettelse")
Function UserExist(samAccountName)
UserExist = False
Set oComputer = GetObject("
WinNT://" & strComputername)
oComputer.Filter = Array("User")
For Each oUser In oComputer
UserExist = (oUser.Name = samAccountName)
If UserExist Then
Exit For
End If
Next
Set oComputer = Nothing
End Function
'***** Script slut *****
:-)