Prev: Extract multiple cabs
Next: excel syntax
From: Paco on 6 May 2010 10:11 Thank you very much. I will try it in a virtual vmware environment next week. I'll be back with the results, and, if it doesn't work, to ask for help. :-) Richard Mueller [MVP] wrote: You can use the NameTranslate object to convert sAMAccountName's 06-May-10 You can use the NameTranslate object to convert sAMAccountName's into distinguishedName's. The script could be similar to below (not tested): ========= Option Explicit Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain Dim objExcel, strExcelPath, objSheet, intRow Dim strOldName, strNewName, strUserDN, objUser, strUPN ' Constants for the NameTranslate object. Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1779 = 1 ' Specify spreadsheet. strExcelPath = "c:\scripts\users.xls" ' Specify UPN suffix. strUPN = "@mycompany.com" ' Determine DNS name of domain from RootDSE. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") ' Use the NameTranslate object to find the NetBIOS domain name from the ' DNS domain name. Set objTrans = CreateObject("NameTranslate") objTrans.Init ADS_NAME_INITTYPE_GC, "" objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) ' Remove trailing backslash. strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) ' Open spreadsheet. Set objExcel = CreateObject("Excel.Application") objExcel.WorkBooks.Open strExcelPath Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) ' Read the spreadsheet. Start with the second row. ' Read until a blank found in column 1. intRow = 2 Do While objSheet.Cells(intRow, 1).Value <> "" strOldName = objSheet.Cells(intRow, 1).Value strNewName = objSheet.Cells(intRow, 2).Value ' Use the Set method to specify the NT format of the user name. ' Trap error if user does not exist. On Error Resume Next objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strOldName If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "User " & strOldName & " does not exist" Else On Error GoTo 0 ' Use the Get method to retrieve the RPC 1779 Distinguished Name. strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) ' Bind to the user object. Set objUser = GetObject("LDAP://" & strUserDN) ' Change sAMAccountName and UPN. objUser.sAMAccountName = strNewName objUser.userPrincipalName = strNewName & strUPN ' Save changes. Trap error if sAMAccountName a duplicate. On Error Resume Next objUser.SetInfo Previous Posts In This Thread: Submitted via EggHeadCafe - Software Developer Portal of Choice Distributed Data Grids - Share Objects Between Windows Service and ASP.NET http://www.eggheadcafe.com/tutorials/aspnet/953ed61f-e440-4ca5-8b7a-1bb00e33db07/distributed-data-grids-.aspx
|
Pages: 1 Prev: Extract multiple cabs Next: excel syntax |