ADSI Fejl ved oprettelse af bruger
Jeg får konstant fejlen:Users.vbs(69, 9) (null): A member could not be added to or removed from the local group because the member does not exist.
Scriptet
Const strComputer = "."
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const ADS_UF_PASSWD_CANT_CHANGE = &H40
SET FSO=CreateObject("Scripting.FileSystemObject")
Set Computer= GetObject("WinNT://"&strComputer&",computer")
SET AdminGroup = GetObject("WinNT://"&strComputer&"/Administrators,group")
'Her skulle den sætte brugeren ind i gruppen ikke ??
SET UserGroup = GetObject("WinNT://"&strComputer&"/IIS_WPG,group")
Computer.Filter = Array("user")
UserName = ""
Password = ""
FullName = ""
Description = ""
Set CSVFile = fso.OpenTextFile("C:\users.csv",1)
Set LogFile = fso.OpenTextFile("C:\usersresults.TXT",2,True)
X = 0
UsersCreated=0
Do While CSVFile.AtEndOfStream <> True
Result = ""
X = X + 1
Data = CSVFile.Readline
UserAttributes = Split(Data, ",")
If Ubound(UserAttributes,1) >= 4 Then
IsAdmin = False
UserName = UserAttributes(0)
Fullname = UserAttributes(1)
Password = UserAttributes(2)
Description = UserAttributes(3)
IsAdmin = UserAttributes(4)
If Not (IsAdmin = "False") and Not (IsAdmin = "True") and Not (IsAdmin = "0") and Not (IsAdmin = "1") Then IsAdmin = False
CreateUser = True
For Each UserObject In Computer
If UCASE(UserObject.name) = UCASE(UserName) Then
LogFile.Writeline("User "&Username&" ("&Fullname&") already existed.")
CreateUser = False
End If
Next
If CreateUser Then
Set User = Computer.Create("user", UserName)
If Password <> "" Then User.SetPassword Password else User.SetPassword "password"
If Description <> "" Then User.Description = Description
User.Fullname = Fullname
User.SetInfo
objUserFlags = User.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
User.Put "userFlags", objPasswordExpirationFlag
User.SetInfo
objUserFlags = User.Get("UserFlags")
objPasswordCannotChange = objUserFlags OR ADS_UF_PASSWD_CANT_CHANGE
User.Put "userFlags", objPasswordCannotChange
User.SetInfo
'Her knækker scriptet og siger at brugeren ikke findes
UserGroup.Add User.ADsPath
If IsAdmin Then AdminGroup.Add User.ADsPath
Result = UserName&" ("&Fullname&") was created. "
If Password <> "" Then Result = Result + "Password was given a custom entry." else Result = Result + "Password was set to ""password""."
If Description <> "" Then Result = Result + " Description was set."
If IsAdmin Then Result = Result + " User was made a member of Administrators."
Result = Result + Chr(13)
LogFile.Writeline(Result)
UsersCreated = UsersCreated + 1
End If
Else
LogFile.Writeline("The entry on line "&X&" has less than 5 elements (Username,Fullname,Password,Description,AdminTrueFalse) and will not be processed.")
LogFile.Writeline("Username and Fullname are mandatory, the other elements can be null (ie. ,,), but the correct number of commas must be present.")
End If
Loop
CSVFile.Close
LogFile.Close
Result = "Done!"&Chr(13)&X&" lines of CSV file processed - "&UsersCreated&" Users Created!"&Chr(13)&"See the log file in C:\usersresults.TXT for details!"
wsh.echo Result
