![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Help with a script Hello, I need help with a script, I have about 400 security groups that I need to rename, all the groups are listed on a spreadsheet. What I would like to do is change all the groups where I put a U- for Universal groups and G- for all global groups and a L- for all local groups in front of the name. I have 2 colums on the spreadsheet, one with the old name and one with the new name... does anyone know if this is possible? Thanks Gavin... |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Help with a script Gavin wrote: Quote: > > I need help with a script, I have about 400 security groups that I need to > rename, all the groups are listed on a spreadsheet. What I would like to > do is change all the groups where I put a U- for Universal groups and G- > for all global groups and a L- for all local groups in front of the name. > I have 2 colums on the spreadsheet, one with the old name and one with the > new name... does anyone know if this is possible? the spreadsheet, rather than Common Names or Distinguished Names. Common Names do not uniquely identify the groups, although generally the Common Name (value of the cn attribute) and NT names (value of the sAMAccountName attribute) are the same. I assume that below. You will need to use the NameTranslate object to convert the NT names into Distinguished Names (DN's). Then you would use the MoveHere method of the parent container/OU object to rename the Common Name. You would assign a new value for sAMAccountName. A VBScript program can determine the NetBIOS name of the domain, read the old group NT name in the first column of the spreadsheet, use NameTranslate to convert this to the DN, bind to the group object, read the new name from the second column, modify sAMAccountName, then use the Parent method of the group object to bind to the Parent OU and invoke the MoveHere method to change the cn attribute (Common Name). For example (not tested): =========== ' Constants for NameTranslate object. Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1779 = 1 ' Specify spreadsheet. strFile = "c:\scripts\Groups.xls" ' Determine DNS domain name from RootDSE object. 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 strFile Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) ' Start reading from the first row. intRow = 1 Do While objSheet.Cells(intRow, 1).Value <> "" ' Read old group name from column 1. strOld = objSheet.Cells(intRow, 1).Value ' Read new group name from column 2. strNew = objSheet.Cells(intRow,2).Value ' Use NameTranslate to convert NT name to Distinguished Name. ' Trap error if NT name not found. On Error Resume Next objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strOld If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "Group " & strOld _ & " not found in Active Directory" Else On Error GoTo 0 strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779) ' Bind to group object. Set objGroup = GetObject("LDAP://" & strGroupDN) ' Bind to parent OU/Container object of group. Set objParent = GetObject(objGroup.Parent) ' Rename the group. Set objNewGroup = objParent.MoveHere(objGroup.AdsPath, "cn=" & strNew) ' Modify sAMAccountName (NT name, also called "pre-Windows 2000" name). objNewGroup.sAMAccountName = strNew objNewGroup.SetInfo End If intRow = intRow + 1 Loop ' Close the workbook. objExcel.ActiveWorkbook.Close ' Quit Excel. objExcel.Application.Quit ======== This assumes that all names in the spreadsheet are valid and unique. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Help with a script Richard, Thank you so much, this worked perfectly. "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:%23j%23D00j$IHA.5048@xxxxxx Quote: > Gavin wrote: > Quote: >> >> I need help with a script, I have about 400 security groups that I need >> to rename, all the groups are listed on a spreadsheet. What I would like >> to do is change all the groups where I put a U- for Universal groups and >> G- for all global groups and a L- for all local groups in front of the >> name. I have 2 colums on the spreadsheet, one with the old name and one >> with the new name... does anyone know if this is possible? > It sounds like you have "pre-Windows 2000" names (also called NT names) in > the spreadsheet, rather than Common Names or Distinguished Names. Common > Names do not uniquely identify the groups, although generally the Common > Name (value of the cn attribute) and NT names (value of the sAMAccountName > attribute) are the same. I assume that below. > > You will need to use the NameTranslate object to convert the NT names into > Distinguished Names (DN's). Then you would use the MoveHere method of the > parent container/OU object to rename the Common Name. You would assign a > new value for sAMAccountName. > > A VBScript program can determine the NetBIOS name of the domain, read the > old group NT name in the first column of the spreadsheet, use > NameTranslate to convert this to the DN, bind to the group object, read > the new name from the second column, modify sAMAccountName, then use the > Parent method of the group object to bind to the Parent OU and invoke the > MoveHere method to change the cn attribute (Common Name). For example (not > tested): > =========== > ' Constants for NameTranslate object. > Const ADS_NAME_INITTYPE_GC = 3 > Const ADS_NAME_TYPE_NT4 = 3 > Const ADS_NAME_TYPE_1779 = 1 > > ' Specify spreadsheet. > strFile = "c:\scripts\Groups.xls" > > ' Determine DNS domain name from RootDSE object. > 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 strFile > Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) > > ' Start reading from the first row. > intRow = 1 > Do While objSheet.Cells(intRow, 1).Value <> "" > ' Read old group name from column 1. > strOld = objSheet.Cells(intRow, 1).Value > ' Read new group name from column 2. > strNew = objSheet.Cells(intRow,2).Value > ' Use NameTranslate to convert NT name to Distinguished Name. > ' Trap error if NT name not found. > On Error Resume Next > objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strOld > If (Err.Number <> 0) Then > On Error GoTo 0 > Wscript.Echo "Group " & strOld _ > & " not found in Active Directory" > Else > On Error GoTo 0 > strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779) > ' Bind to group object. > Set objGroup = GetObject("LDAP://" & strGroupDN) > ' Bind to parent OU/Container object of group. > Set objParent = GetObject(objGroup.Parent) > ' Rename the group. > Set objNewGroup = objParent.MoveHere(objGroup.AdsPath, "cn=" & > strNew) > ' Modify sAMAccountName (NT name, also called "pre-Windows 2000" > name). > objNewGroup.sAMAccountName = strNew > objNewGroup.SetInfo > End If > intRow = intRow + 1 > Loop > > ' Close the workbook. > objExcel.ActiveWorkbook.Close > > ' Quit Excel. > objExcel.Application.Quit > ======== > This assumes that all names in the spreadsheet are valid and unique. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Logon Script Causing Laptops To Hang - Problems in script? | VB Script | |||
| problem passing args to script 'There is no script engine for file extenstion' | VB Script | |||
| Include another script, keep variables in included script? | PowerShell | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||
| Can you drag-n-drop a file on top of a PS script to run the script? | PowerShell | |||