Jump to content

Recommended Posts

Posted

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..

Posted

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
'*************************************************************************

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...