Flere URL strings i vbs brugeroprettelse
Jeg bruger følgende vb til at oprette brugere via excel ark.Mit problem består i at jeg ikke kan tilføje mere en 1 url til brugeren, de skulle gerne have 3 (har lag url "manuelt" ind i script, som strurl1 til 3, skal ske viaexcel ark)
vb køre fint igennem, men det er kun den sidste URL der stå i brugeren nå jeg kikker i AD
Hvordan får jeg laget flere URL ind ?
ps, url bruges i logon scrips ;) til at måle hvilke drev de skal have
problemet er de 3 objusr.url
VB start
Option Explicit
Dim objRootLDAP, objContainer, objUser, objGroup, objFSO
Dim objShell, objExcel, objSpread, intRow, intRunError, InputPrompt1
Dim strUser, strOU, strOU1, strCNOU, strdc1, strdc2, strSheet
Dim strBrugernavn, strEfternavn, strFornavn, strInitialer, strKontor
Dim strBeskrivelse, strStilling, strAfdeling, strFirma, strTelefonnr
Dim strEMail, strCN, strFulde_Navn, strPassword, strAdresse, strPostboks
Dim strBy, strRegion, strPostnr, strLand, strLoginnavn, strFax, strOU2
Dim strMedlem_af1, strMedlem_af2, strHomeFolder, strHome,strDomainName
Dim strProfile, strProfileFolder, strUrl1, strUrl2, strUrl3
'Constants
Const sUPNSuffix = "@domain.DK"
strDomainName = "domain.DK"
strdc1 = "dc=DK"
strdc2 = "dc=domain,"
strOU = "OU=02_HS ," ' Note the comma
strOU1 = "OU=02_HS,"
strOU2 = "02_HS"
strCNOU = "OU=OrgGr,"
strHome = "\\domain.DK\DFS\HS\SDB\P\1\"
strProfile = "\\domain.DK\DFS\HS\SDB\$\Profiles\"
strUrl1 = "Q:\\sdbkas.dk\dfs\hs\sdb\q\1"
strUrl2 = "lokation:SDB"
strUrl3 = "Myndighed:HS"
'strSheet = InputBox(InputPrompt1, "UserInitials") '"I:\Bruger\Testi\testi10.xls"
InputPrompt1 = "Domain = "&strDomainName&vbCrLf&"Container = "&strOU2&vbCrLf&vbCrLf&"Sti 0g navn Til Excell XLS, eks
Q:\brugeradm\Excell.xls"
strSheet = InputBox(InputPrompt1)
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
Set objShell = CreateObject("Wscript.Shell")
intRow = 4 'Row 1 often contains headings
Do Until objExcel.Cells(intRow,1).Value = ""
strBrugernavn = Trim(objExcel.Cells(intRow, 1).Value)
strEfternavn = Trim(objExcel.Cells(intRow, 2).Value)
strFornavn = Trim(objExcel.Cells(intRow, 3).Value)
strInitialer = Trim(objExcel.Cells(intRow, 4).Value)
strKontor = Trim(objExcel.Cells(intRow, 5).Value)
strBeskrivelse = Trim(objExcel.Cells(intRow, 6).Value)
strStilling = Trim(objExcel.Cells(intRow, 7).Value)
strAfdeling = Trim(objExcel.Cells(intRow, 8).Value)
strFirma = Trim(objExcel.Cells(intRow, 9).Value)
strTelefonnr = Trim(objExcel.Cells(intRow, 10).Value)
strEMail = Trim(objExcel.Cells(intRow, 11).Value)
strMedlem_af2 = Trim(objExcel.Cells(intRow, 12).Value)
strCN = Trim(objExcel.Cells(intRow, 13).Value)
strFulde_Navn = Trim(objExcel.Cells(intRow, 14).Value)
strPassword = Trim(objExcel.Cells(intRow, 15).Value)
strAdresse = Trim(objExcel.Cells(intRow, 16).Value)
strPostboks = Trim(objExcel.Cells(intRow, 17).Value)
strBy = Trim(objExcel.Cells(intRow, 18).Value)
strRegion = Trim(objExcel.Cells(intRow, 19).Value)
strPostnr = Trim(objExcel.Cells(intRow, 20).Value)
strLand = Trim(objExcel.Cells(intRow, 21).Value)
strLoginnavn = Trim(objExcel.Cells(intRow, 22).Value)
strFax = Trim(objExcel.Cells(intRow, 23).Value)
strMedlem_af1 = Trim(objExcel.Cells(intRow, 24).Value)
Set objUser = objContainer.Create("User", "cn=" & strCN)
objUser.sAMAccountName = strBrugernavn
objUser.givenName = strFornavn
objUser.initials = strInitialer
objUser.sn = strEfternavn
objUser.displayName = strFulde_Navn
objUser.description = strBeskrivelse
objUser.physicalDeliveryOfficeName = strKontor
objUser.telephoneNumber = strTelefonnr
objUser.mail = strEMail
objUser.streetAddress = strAdresse
objUser.postOfficeBox = strPostboks
objUser.l = strBy
objUser.st = strRegion
objUser.postalCode = strPostnr
objUser.c = strLand
objUser.userPrincipalName = strLoginnavn & sUPNSuffix
objUser.Url = strUrl1
objUser.Url = strUrl2
objUser.Url = strUrl3
objUser.profilePath = strProfile & strBrugernavn
objUser.facsimileTelephoneNumber = strFax
objUser.title = strStilling
objUser.department = strAfdeling
objUser.company = strFirma
objUser.SetInfo
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPassword
objUser.SetInfo
Set objUser = GetObject("LDAP://cn="& strBrugernavn & ", " & strOU1 & strdc2 & strdc1)
Set objGroup = GetObject("LDAP://cn=" & strMedlem_af1 & ", " & strCNOU & strOU1 & strdc2 & strdc1)
objGroup.Add(objUser.ADsPath)
Set objGroup = GetObject("LDAP://cn=" & strMedlem_af2 & ", " & strCNOU & strOU1 & strdc2 & strdc1)
objGroup.Add(objUser.ADsPath)
call HomeDir
call Profile
intRow = intRow + 1
Loop
objExcel.Quit
WScript.Echo " Du har oprettet " & intRow - 4 & " brugere i " & strou
Sub HomeDir()
strHomeFolder = strHome & strBrugernavn
If strHomeFolder <> "" Then
If Not objFSO.FolderExists(strHomeFolder) Then
On Error Resume Next
objFSO.CreateFolder strHomeFolder
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "Cannot create: " & strHomeFolder
End If
On Error GoTo 0
End If
If objFSO.FolderExists(strHomeFolder) Then
' Assign user permission to home folder.
intRunError = objShell.Run("%COMSPEC% /c Echo J| cacls " & strHomeFolder & " /T /C /G Administrators:F SYSTEM:F " &
strBrugernavn & ":C", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for admin user " _
& strUser & " to home folder " & strHomeFolder
End If
End If
End If
End Sub
Sub Profile()
strProfileFolder = strProfile & strBrugernavn
If strProfileFolder <> "" Then
If Not objFSO.FolderExists(strProfileFolder) Then
On Error Resume Next
objFSO.CreateFolder strProfileFolder
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "Cannot create: " & strProfileFolder
End If
On Error GoTo 0
End If
If objFSO.FolderExists(strHomeFolder) Then
' Assign user permission to home folder.
intRunError = objShell.Run("%COMSPEC% /c Echo J| cacls " & strProfileFolder & " /T /C /G Administrators:F SYSTEM:F " &
strBrugernavn & ":F", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for admin user " _
& strUser & " to home folder " & strProfileFolder
End If
End If
End If
End Sub
WScript.Quit