Hvis du ikke er helt stiv i WSH så har du her et script jeg har lavet - scriptet opretter brugere, grupper og tildeler rettigheder mm.
'Designtech ApS
'Tommy Pedersen
'Add Workgroup User
'Filformat: Hver linie starter med en ident.: Group eller User
'Group;Groupname;
'User(0);Username(1);Password(2);Groupname1(3);Groupname2(4);Groupname3(5);FullName(6);
' Descr.(7);ProfilePath(8);LogonScript(9);HomeDrive(10);HomeDir(11)
Const ForReading = 1
Const UF_SCRIPT = &H0001
Const UF_ACCOUNTDISABLE = &H0002
Const UF_HOMEDIR_REQUIRED = &H0008
Const UF_LOCKOUT = &H0010
Const UF_PASSWD_NOTREQD = &H0020
Const UF_PASSWD_CANT_CHANGE = &H0040
Const UF_TEMP_DUPLICATE_ACCOUNT = &H0100
Const UF_NORMAL_ACCOUNT = &H0200
Const UF_INTERDOMAIN_TRUST_ACCOUNT = &H0800
Const UF_WORKSTATION_TRUST_ACCOUNT = &H1000
Const UF_SERVER_TRUST_ACCOUNT = &H2000
Const UF_DONT_EXPIRE_PASSWD = &H10000
Const UF_MNS_LOGON_ACCOUNT = &H20000
Dim arrRecord
Dim objUser
Dim colAccounts
Dim objGroup
' Identify local computer name
Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName
On Error Resume Next
'Open CSV-file
set fso = CreateObject ("Scripting.FileSystemObject")
Set tsTextFile = fso.OpenTextFile ("C:\users.csv", ForReading, False)
IF Err.Number <> 0 Then
WScript.echo "Fejl - Filen users.csv findes ikke!"
WScript.Quit 0
End If
'Loop file
While Not tsTextFile.AtEndOfStream ' START OF Loop
'Read and split every line
strRecord = tsTextFile.ReadLine
arrRecord = Split (strRecord, ";")
'Handle Groups
If arrRecord(0) = "Group" Then
Set objGroup = GetObject("
WinNT://" & strComputer & "/" & arrRecord(1) & ",group")
' WScript.echo "Grupperecord: " & Err.Number & " Gruppenavn " & arrRecord(1)
If objGroup Is Nothing Then 'Create if not exist
WScript.echo "Gruppe: " & arrRecord(1) & " oprettet!"
Set colAccounts = GetObject("
WinNT://" & strComputer & ",computer")
Set objGroup = colAccounts.Create("group", arrRecord(1))
objGroup.SetInfo
Else
WScript.echo "Gruppe: " & arrRecord(1) & " findes allerede!"
End If
End If
'Handle Users
If arrRecord(0) = "User" Then
Set objUser = GetObject("
WinNT://" & strComputer & "/" & arrRecord(1) & ",user")
' WScript.echo "Userrecord: " & Err.Number & " Usernavn " & arrRecord(1)
If objUser Is Nothing Then 'Create if not exist
WScript.echo "Bruger: " & arrRecord(1) & " oprettet!"
Set colAccounts = GetObject("
WinNT://" & strComputer & ",computer")
Set objUser = colAccounts.Create("user", arrRecord(1))
Else
WScript.echo "Bruger: " & arrRecord(1) & " rettes!"
End if
objUser.SetPassword arrRecord(2)
objUser.UserFlags = objUser.UserFlags Or UF_DONT_EXPIRE_PASSWD Or UF_PASSWD_CANT_CHANGE
objUser.FullName = arrRecord(6)
objUser.Description = arrRecord(7)
objUser.Profile = arrRecord(8)
objUser.LoginScript = arrRecord(9)
objUser.HomeDirDrive = arrRecord(10)
objUser.HomeDirectory = arrRecord(11)
objUser.SetInfo
For Each grp In objUser.Groups
'grp.Delete
Next
'Connect Users to Groups
If arrRecord(3) then
Set objGroup = GetObject("
WinNT://" & strComputer & "/" & arrRecord(3) & ",group")
If objUser Then 'Add if group exist
Set objUser = GetObject("
WinNT://" & strComputer & "/" & arrRecord(1) & ",user")
objGroup.Add(objUser.ADsPath)
End if
End if
If arrRecord(4) then
Set objGroup = GetObject("
WinNT://" & strComputer & "/" & arrRecord(4) & ",group")
If objUser Then 'Add if group exist
Set objUser = GetObject("
WinNT://" & strComputer & "/" & arrRecord(1) & ",user")
objGroup.Add(objUser.ADsPath)
End if
End if
If arrRecord(5) then
Set objGroup = GetObject("
WinNT://" & strComputer & "/" & arrRecord(5) & ",group")
If objUser Then 'Add if group exist
Set objUser = GetObject("
WinNT://" & strComputer & "/" & arrRecord(1) & ",user")
objGroup.Add(objUser.ADsPath)
End if
End if
End If
Set objUser = Nothing
Set colAccounts = Nothing
Set objGroup = Nothing
Wend