bio Posted September 10, 2009 Posted September 10, 2009 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..
bio Posted September 10, 2009 Author Posted September 10, 2009 No need anymore... Got it together now bio... 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 '*************************************************************************
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now