+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, How to bulk rename local groups ? in Coding and Web Development; Does anyone know how to accomplish this : We have a windows server named server1 with many local groups. These ...
  1. #1
    bio
    bio is offline
    bio's Avatar
    Join Date
    Apr 2008
    Location
    netherlands
    Posts
    520
    Thank Post
    16
    Thanked 130 Times in 102 Posts
    Rep Power
    38

    Lightbulb How to bulk rename local groups ?

    Does anyone know how to accomplish this :

    We have a windows server named server1 with many local groups. These groups need to be renamed.
    I want to use Excel or a textfile that has 2 columns ...the first column contains the current groupname and the second one contains the new name.

    Does anyone know a VBS/WMI script to accomplish this ?

    regards
    bio..

  2. #2
    bio
    bio is offline
    bio's Avatar
    Join Date
    Apr 2008
    Location
    netherlands
    Posts
    520
    Thank Post
    16
    Thanked 130 Times in 102 Posts
    Rep Power
    38
    No need anymore...
    Got it together now

    bio...

    Code:
    Option Explicit
    Dim	objExcel, objExcelWorkbook, objExcelCurrentRow
    Dim 	objOldName,objNewName
    Dim 	setattribute,objWMIService,objAccount,colAccounts
    
    Const ForReading = 1
    Const strComputer = "."
    Const strExcelFileName = "E:\Localgroups.xls"
    
    '***********************************************************************
    '*************************** MAINSCRIPT *******************************
    '***********************************************************************
    Set objExcel = CreateObject("Excel.Application")
    Set objExcelWorkbook = objExcel.Workbooks.Open(strExcelFileName)
    
    'Column 1 (A) : Old Name
    'Column 2 (B) : New Name
    objExcelCurrentRow = 2
    Do Until objExcel.Cells(objExcelCurrentRow, 1).Value=""
    	objOldName = Trim(objExcel.Cells(objExcelCurrentRow, 1).Value)
    	objNewName = Trim(objExcel.Cells(objExcelCurrentRow, 2).Value)
    	Call RenameLocalGroup
    	objExcelCurrentRow = objExcelCurrentRow + 1	
    Loop
    objExcel.Quit
    
    '*************************************************************************
    '***********************     Subroutines      ****************************
    '*************************************************************************
    Sub RenameLocalGroup
    	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    	Set colAccounts = objWMIService.ExecQuery ("SELECT * FROM Win32_Account WHERE LocalAccount = True AND Name = '" & objOldName & "'")
    			For Each objAccount In colAccounts
    			objAccount.Rename objNewName
    		Next
    	End Sub
    '*************************************************************************

SHARE:
+ Post New Thread

Similar Threads

  1. Rename Users in bulk?
    By maniac in forum How do you do....it?
    Replies: 8
    Last Post: 24th August 2013, 02:37 PM
  2. Create bulk ad groups from a csv file
    By ful56_uk in forum Windows
    Replies: 2
    Last Post: 20th July 2009, 05:06 PM
  3. Rename and Copy local file to Server
    By mrforgetful in forum How do you do....it?
    Replies: 4
    Last Post: 26th February 2008, 02:56 PM
  4. Replies: 2
    Last Post: 16th January 2008, 04:25 PM
  5. Bulk Change Local Administrator Passwords.
    By Nij.UK in forum Windows
    Replies: 14
    Last Post: 15th June 2007, 01:45 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •